jdergon 发表于 2015-4-7 13:55:26

Skill 语法解释

procedure( trListOfSquares( aList )
       let( ( filterdList ) ;定义一个局部变量
             filterList = setof( element aList oddp( element ) ); 得到列表中的奇数
             foreach( mapcar element filterdList ;觉得这行符合foreach的语法吗?
                        element * element          ;mapcar为什么写在这个位置并且mapcar的一个参数不是
            );end of foreach                            ;u_fun吗。
       );end of let
希望得到Skill能人的解答。谢谢
);end of trListOfSquares

jdergon 发表于 2015-4-7 13:57:24

函数的功能是,对一个列表中的奇数求平方
如: trListOfSquares( '(1 2 3 4 5 6 7) ) ===>(1 9 25 49 )

vivienluo 发表于 2015-4-7 22:18:23

你参考下foreach就知道了。

Advanced Usage

The foreach function typically expands to call mapc; however, you can also request that a specific mapping function be applied by giving the name of the mapping function as the first argument to foreach. Thus, foreach can be used as an extremely powerful tool to construct new lists.

Note:Mapping functions are not accepted when this form is applied to association tables.

foreach( mapcar x '(1 2 3) (x >1))=> (nil t t)
foreach( mapcan x '(1 2 3) if((x > 1) ncons(x))) => (2 3)
foreach( maplist x '(1 2 3) length(x)) => (3 2 1)

jdergon 发表于 2015-4-13 10:30:18

谢谢,:lol:lol
页: [1]
查看完整版本: Skill 语法解释