SKILL Language Functions
11月 11, 2021
Tiny_Y
Cadence® SKILL 是一种基于流行的人工智能语言 Lisp 的高级交互式编程语言。
Cadence Skill List
Cadence Skill 字串(Text)
prog
prog后的参数仅在Functions内部时有效,跳出时则不再生效
允许局部变量绑定并允许在控制跳转时突然退出。 这是一种语法形式。
prog 的第一个参数是在 prog 的上下文中声明为局部变量的列表。 除非遇到 go 或 return 等控制转移语句之一,否则 prog 后面的表达式将按顺序执行。 如果没有执行 return 语句,并且在执行最后一个表达式后控制只是“落入”prog,那么 prog 的计算结果为 nil。 如果在 prog 中执行 return,则 prog 立即返回并返回给 return 语句的参数值。
prog 中的任何语句前面都可以有一个符号作为语句的标签。 除非需要多个返回点或者您正在使用 go 函数,否则应该在 prog 上使用更快的绑定局部变量的构造 let 。
x = "hello"
=> "hello"
prog( (x y) ; Declares local variables x and y.
x = 5 ; Initialize x to 5.
y = 10 ; Initialize y to 10.
return( x + y )
)
=> 15
x
=> "hello" ; The global x keeps its original value.
let – SKILL mode
为仅绑定局部变量的 prog 提供更快的替代方案。这是一种语法形式。
Let定义的变量仅在其程序局部有效,不影响也不继承外部或全局变量
x = 5
let( ((x '(a b c)) y)
println( y ) ; Prints nil.
x)
=> (a b c) ; Returns the value of x.
procedure( test( x y )
let( ((x 6) (z "return string"))
if( (equal x y)
then z
else nil)))
test( 8 6 ) ; Call function test.
=> "return string" ; z is returned because 6 == 6.
return
强制封闭程序退出并返回给定值。 return 语句仅在 prog 语句中使用时才有意义。
go 和 return 都不是纯粹的功能,因为它们以非标准方式转移控制权。 也就是说,它们不会返回给调用者。
procedure( summation(l)
prog( (sum temp)
sum = 0
temp = l
while( temp
if( null(car(temp))
then
return(sum)
else
sum = sum + car(temp)
temp = cdr(temp)
)
)
)
)
Returns the summation of previous numbers if a nil is encountered.
summation( '(1 2 3 nil 4))
=> 6 ; 1+2+3
summation( '(1 2 3 4))
=> nil ; prog returns nil if no explicit return)
makeTable
创建一个空的关联表
yTable = makeTable("atable1" 0) => table:atable1
myTable[1] => 0
If you specify a default value when you create the table, the default value is returned if a nonexistent key is accessed.
myTable2 = makeTable("atable2") => table:atable2
myTable2[1] => unbound
If you do not specify a default value when you create the table, the symbol unbound is returned if an undefined key is accessed.
myTable[1] = "blue" => blue
myTable["two"] = '(r e d) => (r e d)
myTable['three] = 'green => green
You can refer to and set the contents of an association table with the standard syntax for accessing array elements.
myTable['three] => green
defstruct
创建一个 defstruct,一个命名结构,它是一个或多个变量的集合。
Defstructs 可以具有不同类型的slots,这些 slots 组合在一个name下以进行处理。
defstruct 形式还创建了一个实例化function,名为 make_<name>,其中 <name> 是提供给 defstruct 的结构体名称
defstruct 可以包含其他 defstruct 的instances;因此需要注意 defstruct 共享。如果不需要共享,可以使用特殊的复制功能来生成被插入 defstruct 的副本。 defstruct 形式还为给定的 defstruct 创建了一个名为 copy_ <name> 的函数。这个函数接受一个参数,一个 defstruct 的实例。它创建并返回给定实例的副本。在其他 defstruct 函数的描述之后会出现一个示例。
defstruct(myStruct slot1 slot2 slot3) => t
struct = make_myStruct(?slot1 "one" ?slot2 "two"
?slot3 "three")
struct->slot1 => "one"
Returns the value associated with a slot of an instance.
struct->slot1 = "new" => "new"
Modifies the value associated with a slot of an instance.
struct->? => (slot3 slot2 slot1)
Returns a list of the slot names associated with an instance.
struct->?? => (slot3 "three" slot2 "two" slot1 "new")
Returns a property list (not a disembodied property list) containing the slot names and values associated with an instance.
boundp
Skill中的变量可以不用提前声明。当程序在一段代码中遇到一个变量时,Skill 会自动创建该变量
当 SKILL 创建一个变量时,将会附一个 unbound 初值给变量表明该变量还未初始化。可使用 boundp 函数判断一个变量是否是 bound。boundp函数具有以下功能:
如果变量为 bound ,返回 t
如果不是 bound ,返回 nil
x = 5 ; Binds x to the value 5.
y = 'unbound ; Unbind y
boundp( 'x )
=> t
boundp( 'y )
=> nil
y = 'x ; Bind y to the constant x.
boundp( y )
=> t ; Returns t because y evaluates to x,
; which is bound.
使用赋值操作符可以给变量赋一个值。我们可通过变量名获得变量的值。
可通过使用 type 函数判断一个变量当前存储的数据类型。如下:
lineCount = 4 => 4
lineCount => 4
type( lineCount ) => fixnum
lineCount = "abc" => "abc"
lineCount => "abc"
type( lineCount ) => string
sklint
检查 SKILL 文件并报告潜在错误和简化代码的方法。
sklint(?file "D:\\SPB_Data\\pcbenv\\ceshi.il")
measureTime
测量计算表达式所需的时间并返回四个数字的列表。 这是一种语法形式。
第一个数字是用于进程的用户 CPU 时间量(以秒为单位)。
第二个数字是内核用于进程的 CPU 时间量。
第三个也是最重要的数字是计算表达式所花费的总时间,以秒为单位。
第四个数字是在计算表达式期间发生的页面错误数。
myList = nil ; Initializes the variable myList.
measureTime( for( i 1 10000 myList = cons(i myList) ) )
=> (0.4 0.05 0.4465 0)
myList = nil ; Initializes the variable myList.
measureTime( for( i 1 1000 myList = append1(myList i) ) )
=> (5.04 0.03 5.06 0)
difference
做减法
difference(5 4 3 2 1) => -5
difference(-12 13) => -25
difference(12.2 -13) => 25.2
abs
取绝对值
abs(-209.625)=> 209.625
abs(23)=> 23
getVarWriteProtect – SKILL mode only
setVarWriteProtect – SKILL mode only
theEnvironment – SKILL++ mode only
11月 11, 2021
Tiny_Y