我在网上找到了本课的代码(http://groups.csail.mit.edu/mac/ftpdir/6.001-fall91/ps4/matcher-from-lecture.scm),我有一段时间了试图调试它.该代码看起来与Sussman所写的相当:
;;; Scheme code from the Pattern Matcher lecture
;; Pattern Matching and Simplification
(define (match pattern expression dictionary)
(cond ((eq? dictionary 'failed) 'failed)
((atom? pattern)
(if (atom? expression)
(if (eq? pattern expression)
dictionary
'failed)
'failed))
((arbitrary-constant? pattern)
(if (constant? expression)
(extend-dictionary pattern expression dictionary)
'failed))
((arbitrary-variable? pattern)
(if (variable? expression)
(extend-dictionary pattern expression dictionary)
'failed))
((arbitrary-expression? pattern)
(extend-dictionary pattern expression dictionary))
((atom? expression) 'failed)
(else
(match (cdr pattern)
(cdr expression)
(match (car pattern)
(car expression)
dictionary)))))
(define (instantiate skeleton …Run Code Online (Sandbox Code Playgroud) 在尝试通过SICP(可能同时观看部分/全部MIT 6.001视频)的背景下,使用MIT Scheme与使用DrScheme的优缺点是什么?
scheme/racket或clojure贝叶斯分类库的任何指针?我需要一个玩具/学习项目,我将要做的.
我想在Racket中创建一个可以接受关键字参数的语法形式,这是某些函数的方式.
把它简化为一个简单的例子,我试着写:
(define-syntax sum-of-products
(syntax-rules (#:extra)
[(sum-of-products ([a b] ...))
(+ (* a b) ...)]
[(sum-of-products ([a b] ...) #:extra extra)
(+ extra (* a b) ...)]))
Run Code Online (Sandbox Code Playgroud)
这样以下就可以了:
(sum-of-products ([2 2] [3 3])) ? 13
(sum-of-products ([2 2] [3 3]) #:extra 5) ? 18
Run Code Online (Sandbox Code Playgroud)
不幸的是,Racket称这种"语法错误",显然这种尝试不正确.
可以这样做吗?
在我正在Racket中工作的应用程序中,我需要获取一个数字列表并将列表分成连续数字的子列表:(在实际应用中,我实际上是分区对由数字和一些数据组成的对,但原则是一样的.)
即如果我的程序被调用,chunkify那么:
(chunkify '(1 2 3 5 6 7 9 10 11)) -> '((1 2 3) (5 6 7) (9 10 11))
(chunkify '(1 2 3)) -> '((1 2 3))
(chunkify '(1 3 4 5 7 9 10 11 13)) -> '((1) (3 4 5) (7) (9 10 11) (13))
(chunkify '(1)) -> '((1))
(chunkify '()) -> '(())
Run Code Online (Sandbox Code Playgroud)
等等
我在Racket中提出了以下内容:
#lang racket
(define (chunkify lst)
(call-with-values
(lambda ()
(for/fold ([chunk '()] [tail '()]) ([cell (reverse lst)])
(cond
[(empty? …Run Code Online (Sandbox Code Playgroud) DrRacket运行R5RS表示这1###是一个完全有效的Scheme号,并打印出一个值1000.0.这让我相信英镑符号(#)表示数字不精确,但我不确定.该规范还说它是一个数字文字的有效语法,但它没有说明这些符号的含义.
有关计划编号文字中#符号的重要信息吗?
我想设置我的球拍REPL交互使用的语言,如下所示:
-> #lang typed/racket
; readline-input:15:0: read: #lang not enabled in the current context [,bt for
; context]
; typed/racket: undefined;
; cannot reference undefined identifier
; [,bt for context]`
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
-> ,bt
; typed/racket: undefined;
; cannot reference undefined identifier
Run Code Online (Sandbox Code Playgroud)
我的错误是什么?
我正在尝试使用jsonTyped Racket中的包,但是我在处理如何键入jsexpr?谓词方面遇到了一些麻烦.我的第一次尝试就是使用#:opaque.
(require/typed json
[#:opaque JSExpr jsexpr?])
Run Code Online (Sandbox Code Playgroud)
麻烦的是,一个jsexpr是不是一个结构,jsexpr?仅仅是测试给定值是否符合某个特定结构的谓语.事实上,JSExpr类型看起来应该是这样的.
(define-type JSExpr (U
'null Boolean String Integer Inexact-Real
(Listof JSExpr) (HashTable Symbol JSExpr)))
Run Code Online (Sandbox Code Playgroud)
那么,我会使用那种JSExpr类型,但仍然存在问题.现在我有一个(U JSExpr EOF)类型,我需要将它转换为一个JSExpr类型(如果我得到EOF,我想抛出一个异常).因此,我想做这样的事情:
(cond
[(jsexpr? json-data) json-data]
[else (error "failed to parse JSON data")])
Run Code Online (Sandbox Code Playgroud)
这应该适用于Racket的发生类型,但现在我还没有jsexpr?定义!幸运的是,存在define-predicate为我生成该功能.不幸的是,它不适用于该JSExpr类型,因为谓词需要一个平坦的契约,以及可能可变的数据结构,例如HashTable需要陪护合同.
好吧,那么将实际jsexpr?谓词输入到出现类型JSExpr呢?
(require/typed json
[jsexpr? (-> Any Boolean : JSExpr)])
Run Code Online (Sandbox Code Playgroud)
不幸的是, …
背景故事:我在Java中做了很多大型且相对复杂的项目,在嵌入式C编程方面有很多经验.我已经熟悉了scheme和CL语法,并用racket编写了一些简单的程序.
问题:我已经计划了一个相当大的项目,并希望在球拍中做到这一点.我听说过很多的"如果'获取’口齿不清,你会成为一个更好的程序员"等,但每一次我尝试计划或编写一个程序我还是"分解"的任务与接口熟悉的有状态的对象时.
是否有针对lisp的"设计模式"?如何"获得"lisp-family"mojo"?如何逃避面向对象约束你的思考?如何运用强大的宏观设施推动的功能性编程思想?我尝试在github上研究大项目的源代码(例如Light Table)并且更加困惑,而不是开悟.
EDIT1(不那么暧昧的问题):关于这个主题是否有很好的文献,你可以推荐或者是否有用cl/scheme/clojure编写的高质量的开源项目,可以作为一个很好的例子吗?