scheme

find free variables in lambda expression

江枫思渺然 提交于 2019-12-05 16:25:12
问题 Does anyone know how I can figure out the free variables in a lambda expression? Free variables are the variables that aren't part of the lambda parameters. My current method (which is getting me nowhere) is to simply use car and cdr to go through the expression. My main problem is figuring out if a value is a variable or if it's one of the scheme primitives. Is there a way to test if something evaluates to one of scheme's built-in functions? For example: (is-scheme-primitive? 'and) ;Value:

Lexical vs dynamic scoping in terms of SICP's Environment Model of Evaluation

喜夏-厌秋 提交于 2019-12-05 15:23:00
问题 In Section 3.2.2 of SICP the execution of the following piece of code (define (square x) (* x x)) (define (sum-of-squares x y) (+ (square x) (square y))) (define (f a) (sum-of-squares (+ a 1) (* a 2))) (f 5) is explained in terms of this diagram. Each time a function is applied, a new frame is created (labeled by E1 through E4 ) which represents a set of bindings between symbols and values. When a symbol is not bound in a frame, that frame's enclosing environment is queried for a binding of

iOS App 唤醒另一个App

萝らか妹 提交于 2019-12-05 14:57:50
iOS App 唤醒另一个App 网上也有讲这块的,感觉讲得都不是很好。而且有一些细节根本没有讲清楚。这里重写整理一下相关知识点。 主要内容 URL Scheme 是什么? 项目中关键的配置 注意事项 URL Scheme 是什么? iOS 有个特性就是应用将其自身”绑定”到一个自定义 URL scheme 上,该 scheme 用于从浏览器或其他应用中启动本应用。常见的分享到第三方之间的跳转都是基于 Scheme 的。 通过对比网页链接来理解 iOS 上的 URL Schemes ,应该就容易多了。 URL ,我们都很清楚, http://www.apple.com 就是个 URL ,我们也叫它链接或网址; Schemes ,表示的是一个 UR L 中的一个位置——最初始的位置,即 :// 之前的那段字符。比如 http://www.apple.com 这个网址的 Schemes 是 http 。 根据我们上面对 URL Schemes 的使用,我们可以很轻易地理解,在以本地应用为主的 iOS 上,我们可以像定位一个网页一样,用一种特殊的 URL 来定位一个应用甚至应用里某个具体的功能。而定位这个应用的,就应该这个应用的 URL 的 Schemes 部分,也就是开头儿那部分。比如短信,就是 sms: 你可以完全按照理解一个网页的 URL ——也就是它的网址——的方式来理解一个

Scheme assignment

北慕城南 提交于 2019-12-05 14:47:45
When I evaluate the following expression every time I get the value 10. (((lambda (x) (lambda () (set! x (+ x 10)) x)) 0)) However I just modify by abstracting the above procedure with a name and call foo every time the value increments by 10!! (define foo ((lambda (x) (lambda () (set! x (+ x 10)) x)) 0)) Can anybody please explain this? The function you are calling is a counter that returns a number 10 higher every time it's called. In the first case, every time, you are creating a new function and then immediately calling it once and then discarding the function. So every time, you are

Y Combinator implementation Scheme

╄→гoц情女王★ 提交于 2019-12-05 14:36:53
I am really new to scheme functional programming. I recently came across Y-combinator function in lambda calculus, something like this Y ≡ (λy.(λx.y(xx))(λx.y(xx))) . I wanted to implement it in scheme, i searched alot but i didn't find any implementation which exactly matches the above given structure. Some of them i found are given below: (define Y (lambda (X) ((lambda (procedure) (X (lambda (arg) ((procedure procedure) arg)))) (lambda (procedure) (X (lambda (arg) ((procedure procedure) arg))))))) and (define Y (lambda (r) ((lambda (f) (f f)) (lambda (y) (r (lambda (x) ((y y) x))))))) As you

Does Chicken Scheme support complex numbers? If so, why am I getting this error?

只谈情不闲聊 提交于 2019-12-05 13:31:36
I just started learning a little Scheme, and I'm using Dorai Sitaram's Teach Yourself Scheme in Fixnum Days . In said work it is stated: Scheme numbers can be integers (eg, 42) ... or complex ( 2+3i ). Emphasis mine. Note the form. Using the principles I had been taught so far I tried writing a few different programs that dealt with the different kinds of numbers. I ended up writing this extremely simple snippet to test complex numbers: (begin (display 3+4i) (newline) ) Testing this on codepad.org (which uses MzScheme) and Ideone.com (which uses guile) worked perfectly. Now, when I tried it

What are the benefits of letrec?

孤人 提交于 2019-12-05 13:31:21
问题 While reading "The Seasoned Schemer" I've begun to learn about letrec . I understand what it does (can be duplicated with a Y-Combinator) but the book is using it in lieu of recurring on the already define d function operating on arguments that remain static. An example of an old function using the define d function recurring on itself (nothing special): (define (substitute new old l) (cond ((null? l) '()) ((eq? (car l) old) (cons new (substitute new old (cdr l)))) (else (cons (car l)

How to Solve N-Queens in Scheme?

吃可爱长大的小学妹 提交于 2019-12-05 13:23:05
I'm stuck on the extended exercise 28.2 of How to Design Programs . I used a vector of true or false values to represent the board instead of using a list. This is what I've got which doesn't work: #lang Scheme (define-struct posn (i j)) ;takes in a position in i, j form and a board and ; returns a natural number that represents the position in index form ;example for board xxx ; xxx ; xxx ;(0, 1) -> 1 ;(2, 1) -> 7 (define (board-ref a-posn a-board) (+ (* (sqrt (vector-length a-board)) (posn-i a-posn)) (posn-j a-posn))) ;reverse of the above function ;1 -> (0, 1) ;7 -> (2, 1) (define (get-posn

fixed point combinator in lisp

无人久伴 提交于 2019-12-05 13:08:54
;; compute the max of a list of integers (define Y (lambda (w) ((lambda (f) (f f)) (lambda (f) (w (lambda (x) ((f f) x))))))) ((Y (lambda (max) (lambda (l) (cond ((null? l) -1) ((> (car l) (max (cdr l))) (car l)) (else (max (cdr l))))))) '(1 2 3 4 5)) I wish to understand this construction. Can somebody give a clear and simple explanation for this code? For example, supposing that I forget the formula of Y. How can I remember it , and reproduce it long after I work with it ? Will Ness Here's some related answers (by me): Y combinator discussion in "The Little Schemer" Unable to get

Drawing onto canvas% element

三世轮回 提交于 2019-12-05 13:01:10
I have a problem while trying to draw onto a canvas GUI element. I create a frame, a canvas and try to draw on the dc context of the canvas with the draw-line method, but nothing happens. The frame with the canvas is shown, but the line isn't shown on the canvas. (require racket/gui/base) (define frame (new frame% [label "Frame"] [width 500] [height 500])) (define canvas (new canvas% [parent frame])) (define dc (send canvas get-dc)) (send dc draw-line 10 10 200 200) (send frame show #t) Does anybody know where I am wrong in the code above ? Try this: (require racket/gui/base) (define frame