我需要一些帮助来理解Paul Graham的What What Lisp Different中的一些观点.
一个新的变量概念.在Lisp中,所有变量都是有效的指针.值是具有类型而不是变量的值,分配或绑定变量意味着复制指针,而不是它们指向的内容.
符号类型.符号与字符串的不同之处在于您可以通过比较指针来测试相等性.
使用符号树的代码表示法.
整个语言始终可用.读取时间,编译时和运行时之间没有真正的区别.您可以在编译时编译或运行代码,同时在运行时读取或编译代码.
这些点意味着什么?它们在C或Java等语言中有何不同?除了Lisp系列语言之外的任何其他语言现在都有这些结构吗?
如果你不知道的话,Arc是Paul Graham的"100年语言",或者更新的Lisp新版本.它在reddit上大量落后(当reddit很有趣时回来了),并且在去年1月发布了早期版本.
但是从那时起似乎没有发生任何事情 - 论坛几乎已经死了,保罗格雷厄姆自己的网站上没有任何新内容.有人知道发生了什么吗?
任何人都可以在Paul Graham的ANSI Common Lisp第110页中解释一个例子吗?
该示例尝试解释use&rest和lambda来创建函数式编程工具.其中之一是构成函数参数的函数.我找不到任何解释它是如何工作的东西.代码如下:
(defun compose (&rest fns)
(destructuring-bind (fn1 . rest) (reverse fns)
#'(lambda (&rest args)
(reduce #'(lambda (v f) (funcall f v))
rest
:initial-value (apply fn1 args)))))
Run Code Online (Sandbox Code Playgroud)
用法是:
(mapcar (compose #'list #'round #'sqrt)
'(4 9 16 25))
Run Code Online (Sandbox Code Playgroud)
输出是:
((2) (3) (4) (5))
Run Code Online (Sandbox Code Playgroud)
2号线和6号线对我来说看起来特别神奇.任何意见将不胜感激.
保罗格雷厄姆在他的伟大文章"复仇的书呆子"中声称,语言的力量各不相同.他提到了一个很好的练习 - 写一个累加器发生器:
我们想要编写一个生成累加器的函数 - 一个取n的函数,并返回一个函数,它取另一个数字i并返回n递增i.
Java中的解决方案是
public class Accumulator {
public interface Inttoint {
public int call(int i);
}
public static Inttoint foo(final int n) {
return new Inttoint() {
int s = n;
public int call(int i) {
s = s + i;
return s;
}};
}
public static void main(String... args) {
Inttoint accumulator = foo(1);
System.out.println(accumulator.call(2) == 3);
System.out.println(accumulator.call(3) == 6);
}
}
Run Code Online (Sandbox Code Playgroud)
我很好奇,无论是在Java 8(感谢lambda)已经是一些优雅的方式如何写它类似于Groovy,见下文.我试过了Function<Integer, Integer>
但我坚持这个编译器错误.
从lambda表达式引用的局部变量必须是最终的或有效的final
那么你有一些Java 8解决方案吗?
将旧的Java解决方案与Groovy解决方案进行比较 …
我试图找到保罗格雷厄姆的文章,提到"黑客不知道他们是否好"的效果.在其中,他说他(看似虚假的谦卑)说他自己甚至不知道他是否善良.
PS抱歉垒球问题.我确实尝试搜索他的网站,这是徒劳的.
在我的追求,以了解更多F#,我试图执行一个"蓄电池发电机"由保罗·格雷厄姆描述这里.到目前为止,我最好的解决方案是完全动态输入:
open System
let acc (init:obj) : obj->obj=
let state = ref init
fun (x:obj) ->
if (!state).GetType() = typeof<Int32>
&& x.GetType() = typeof<Int32> then
state := (Convert.ToInt32(!state) + Convert.ToInt32(x)) :> obj
else
state := (Convert.ToDouble(!state) + Convert.ToDouble(x)) :> obj
!state
do
let x : obj -> obj = acc 1 // the type annotation is necessary here
(x 5) |> ignore
printfn "%A" (x 2) // prints "8"
printfn "%A" (x 2.3) // prints "10.3"
Run Code Online (Sandbox Code Playgroud)
我有三个问题:
paul-graham ×7
clojure ×2
common-lisp ×2
lisp ×2
accumulator ×1
arc-lisp ×1
closures ×1
f# ×1
java ×1
java-8 ×1
reduce ×1
scheme ×1
security ×1