看完这个页面.我发现很难记住如何使用define-syntax代替define-macro,所以我想define-macro在mit-scheme中实现(或者至少找到一些等价物).
这是我的(有问题的)实现:
(define-syntax define-macro
(rsc-macro-transformer
(let ((xfmr (lambda (macro-name macro-body)
(list 'define-syntax macro-name
(list 'rsc-macro-transformer
(let ((m-xfmr macro-body))
(lambda (e r)
(apply m-xfmr (cdr e)))))))))
(lambda (e r)
(apply xfmr (cdr e))))))
(define-macro my-when
(lambda (test . branch)
(list 'if test (cons 'begin branch))))
(my-when #t
(begin
(display "True")
(newline)))
Run Code Online (Sandbox Code Playgroud)
REPL抱怨说:
;The object (lambda (test . branch) (list (quote if) test (cons (quote begin) branch))) is not applicable.
Run Code Online (Sandbox Code Playgroud)
我刚接触计划并且不知道出了什么问题,有人可以帮助我吗?
鉴于函数的骨架:
(define gen-hash-division-method (lambda (size)))
Run Code Online (Sandbox Code Playgroud)
以及:
(define hash-1 (gen-hash-division-method 701))
Run Code Online (Sandbox Code Playgroud)
我编码的内容:
(define gen-hash-division-method
(lambda (size)
(lambda (w)
(modulo key(flip(w)) size))))
Run Code Online (Sandbox Code Playgroud)
key(flip(w))获取一个列表w并返回一个整数.
并致电:
(hash-1 '(h e l l o))
Run Code Online (Sandbox Code Playgroud)
我一直收到这个错误:
procedure application: expected procedure, given: (h e l l o) (no arguments)
Run Code Online (Sandbox Code Playgroud) SRFI 42中的急切理解可以有一个:while在某些条件成立时运行生成器的子句,例如:(list-ec (:while (:range i 10) (< (* i i) 50)) i)返回列表(0 1 2 3 4 5 6 7)(并停止 7处的迭代,不像是if,如(list-ec (:range i 10) (if (< (* i i) 50)) i)将继续运行,但不会产生更多值).
在拍,我一般喜欢使用原生for和for/list,但他们似乎并不具备这样的内置.什么是:while在Racket中模拟的最佳方式for?
我不太确定这个问题出现了什么,我从来没有太多关于着色器的经验所以它可能与实际的着色器无关(很可能问题不在着色器中)
我有这个结果

片段着色器
#version 120
void main(void) {
gl_FragColor[0] = 0.0;
gl_FragColor[1] = 0.0;
gl_FragColor[2] = 0.0;
}
Run Code Online (Sandbox Code Playgroud)
顶点着色器
#version 120
attribute vec2 coord2d;
void main(void) {
gl_Position = vec4(coord2d, 0.0, 1.0);
}
Run Code Online (Sandbox Code Playgroud)
我的渲染功能
(define (renderFunc)
(gl:Clear gl:COLOR_BUFFER_BIT)
(gl:UseProgram program)
(gl:EnableVertexAttribArray attribute_coord2d)
(gl:Begin gl:TRIANGLES)
(gl:Vertex3f 0.0 0.8 0)
(gl:Vertex3f -0.8 -0.8 0)
(gl:Vertex3f 0.8 -0.8 0)
(gl:End)
(gl:DisableVertexAttribArray attribute_coord2d)
(glut:SwapBuffers))
Run Code Online (Sandbox Code Playgroud)
和我的Init功能
(define (initFunc)
(gl:ClearColor 1 1 1 1)
(gl:Enable gl:TEXTURE_2D)
(gl:Enable gl:LIGHTING)
(gl:Enable gl:BLEND)
(gl:BlendFunc gl:SRC_ALPHA gl:ONE_MINUS_SRC_ALPHA)
(set! program (CreatePorgram …Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数,try-weak-cues用于从大量响应中选择响应.该程序本质上是与用户的对话.
(define try-weak-cues
(lambda (sentence context)
(define helper
(lambda(list-of-pairs)
(define helper2
(lambda(list-of-pairs context)
(cond((null? list-of-pairs)
(cond((null? list-of-pairs) '())
((any-good-fragments?(cue-part(car list-of-pairs))sentence) (helper2(cdr(car list-of-pairs))context))
(else(helper(cdr list-of-pairs)))))))))
(helper *weak-cues*))))
Run Code Online (Sandbox Code Playgroud)
下面是该函数应该从中获取的响应列表:
(define *weak-cues*
'( ( ((who) (whos) (who is))
((first-base)
((thats right) (exactly) (you got it)
(right on) (now youve got it)))
((second-base third-base)
((no whos on first) (whos on first) (first base))) )
( ((what) (whats) (what is))
((first-base third-base)
((hes on second) (i told you whats on second)))
((second-base)
((right) …Run Code Online (Sandbox Code Playgroud) 我的任务有点麻烦.我必须创建一个请求列表和元素列表的过程,然后继续将元素添加到每个子列表中的第一个位置.我设法做到了,它看起来像这样:
(define (add-element lst elem)
(foldr cons lst (list elem)))
(define (insert-first lst1 x)
(cond
[(empty? lst1) empty]
[else (local [(define insert (add-element(first lst1) x))]
(cons insert (insert-first (rest lst1) x)))]))
Run Code Online (Sandbox Code Playgroud)
所以,如果你要输入,(insert-first '((a b) (c d))你最终会得到(list (list 'x 'a 'b) (list 'x 'c 'd))
唯一的问题是我需要使用map和编写程序local.后者我认为我已经完成了但我不能为我的生活找到一种方法来使用map.
我试图在ACL2s/Lisp中证明这个函数,但它返回一个堆栈溢出错误,虽然我看不到代码中的缺陷.
(defunc foo (x y)
:input-contract (and (natp x) (natp y))
:output-contract (natp (foo x y))
(cond ((equal 0 x) (+ y 1))
((equal 0 y) (foo (- x 1) 1))
(t (foo (- x 1) (foo x (+ y 1))))))
Run Code Online (Sandbox Code Playgroud) 以下函数是尾递归的吗?如果没有,我可以做些什么来修改它?
(define (euclids-alg n1 n2)
(cond((= n1 0) n2)
((= n2 0) n1)
((= n1 n2) n1)
((> n1 n2) (euclids-alg (- n1 n2) n2))
((< n1 n2) (euclids-alg n1 (- n2 n1)))))
Run Code Online (Sandbox Code Playgroud) 我试图定义一个像'(()())这样的数据结构初始化函数,这样我以后就可以生成很多.
在我定义它之后,init函数可以正常工作.但是在我使用set-car之后!在(let*...)函数调用中,(init)的行为发生了变化.
我的问题是如何解释这种行为?
; define init func
(define (init)
(display "initializing goal space...")
(newline)
'(() ())
)
; call init func
(init)
; use set-car! in (let* ...)
(let*
((x (init)))
(display x)
(newline)
(set-car! x (list 'foo))
(display x)
(newline)
)
; call init func again
(init)
Run Code Online (Sandbox Code Playgroud)
DrScheme中的输出日志,lang = Textual(MzScheme,包括R5RS)
Welcome to DrScheme, version 372 [3m].
Language: Textual (MzScheme, includes R5RS).
initializing goal space...
(() ())
initializing goal space...
(() ())
((foo) ())
initializing goal space...
((foo) ())
>
Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的问题,几个小时无法在Scheme中实现.假设我们有:
(define x '( (Orlando (NY 3))
(Chicago (Montana 5) (Orlando 8))
...and so on ...
)
Run Code Online (Sandbox Code Playgroud)
我想把它改造成
'( (Orlando NY)
(Chicago Montana Orlando)
...and so on ...
)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
scheme ×10
lisp ×5
racket ×5
glsl ×1
hash ×1
list ×1
mit-scheme ×1
opengl ×1
recursion ×1
termination ×1