racket

streams in racket

怎甘沉沦 提交于 2019-11-30 19:56:44
Can anyone help me better understand how to write a stream? I understand that a stream is an infinite sequence of values and the way I have learned programming them is a representing them as a thunk that when called produces a pair of (1) the first element in the sequence and (2) a thunk that represents the stream for the second-through-infinity elements For example: (define powers-of-two (letrec ([f (lambda (x) (cons x (lambda () (f (* x 2)))))]) (lambda () (f 2)))) I understand here that it is just producing a powers of two and to access these for example calling (car (powers-of-two)) would

Setting Racket Geiser Emacs Path

不羁的心 提交于 2019-11-30 18:35:15
I'm trying to get Geiser's REPL to work in Emacs, but it doesn't seem to be able to find Racket. racket is on my path, but anytime I type run-geiser followed by racket it complains: Unable to start REPL: Searching for program: no such file or directory, racket I read in the Geiser docs that I may have to manually tell Geiser where to find racket , but I can't tell where to configure this property of Geiser. Thanks for your help. Scott Klarenbach Ok, so I added: (setq geiser-racket-binary "/home/user/racket/bin/racket") to my .emacs file after loading geiser.el . I was expecting a configuration

Type of Define expression in Scheme

蹲街弑〆低调 提交于 2019-11-30 17:00:30
问题 To put it simply: My question is whats is the type of a define expression in Scheme? Take for example: (define x 5) or (define x (lambda (n) (* n n))) It's a bit confusing for me. Can anyone help? 回答1: In Racket define is a special form and not an expression, so it doesn't have a value per-se, if you try to execute something like this you'll get an error: (display (define x 42)) => define: not allowed in an expression context in: (define x 42) If it were to have a value it'd be something akin

Setting Racket Geiser Emacs Path

瘦欲@ 提交于 2019-11-30 16:51:48
问题 I'm trying to get Geiser's REPL to work in Emacs, but it doesn't seem to be able to find Racket. racket is on my path, but anytime I type run-geiser followed by racket it complains: Unable to start REPL: Searching for program: no such file or directory, racket I read in the Geiser docs that I may have to manually tell Geiser where to find racket , but I can't tell where to configure this property of Geiser. Thanks for your help. 回答1: Ok, so I added: (setq geiser-racket-binary "/home/user

Pros and cons of MIT Scheme and DrScheme for studying SICP [closed]

倾然丶 夕夏残阳落幕 提交于 2019-11-30 14:01:05
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What are the pros and cons of using MIT Scheme versus using DrScheme, in the context of trying to go through SICP (presumably

Mysterious Racket error: define: unbound identifier; also, no #%app syntax transformer is bound in: define

大憨熊 提交于 2019-11-30 13:28:29
This program produces an error: define: unbound identifier; also, no #%app syntax transformer is bound in: define When pasted into the REPL (to be exact, the last line: (displayln (eval-clause clause state ))), it works. When run in definition window, it fails. I don't know why. #lang racket (define *state* '((a false) (b true) (c true) (d false))) (define *clause* '(a (not b) c)) (define (eval-clause clause state) (for ([x state]) (eval `(define ,(first x) ,(second x)))) (eval (cons 'or (map eval clause)))) (displayln (eval-clause *clause* *state*)) This too: (define (eval-clause clause state

mcons in dr racket

喜夏-厌秋 提交于 2019-11-30 12:44:47
I'm having trouble reading output from dr racket. By default it displays lists using mcons. For example, sicp exercise 2.32 produces: > (subsets (list 1 2 3)) (mcons (mcons '() (mcons (mcons 3 '()) (mcons (mcons 2 '()) (mcons (mcons 2 (mcons 3 '())) (mcons (mcons 1 '()) (mcons (mcons 1 (mcons 3 '())) (mcons (mcons 1 (mcons 2 '())) (mcons (mcons 1 (mcons 2 (mcons 3 '()))) '())))))))) '()) I'm having trouble reading this. Is there a way to make the output look like: (() (3) (2) (2 3) (1) (1 3) (1 2) (1 2 3)) Thanks! Do you know what language are you using in your #lang line? The rest of the

Writing a formal language parser with Lisp

£可爱£侵袭症+ 提交于 2019-11-30 07:10:37
My company is designing a new domain specific scripting language; I have to implement a parser that translates our brand new programming language into a common scripting language so as to be able to enact it. The usual way I do this is by means of Bison and Flex tools that generate the C/C++ code of the translator. I found other tools, for most of the mainstream programming languages, but none for Lisp . Hasn't Lisp ever been used for that? What is the usual way to write a parser with Lisp ? Note: to me, any Lisp implementation / dialect that could help is ok, I do not have any preference. To

Racket Programming. Where am I going wrong?

假装没事ソ 提交于 2019-11-30 06:04:58
问题 The question i'm trying to answer: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Where am I going wrong? my prime? test seems to be the issue, but it works fine on relatively small numbers. However the prime? test gives a wrong answer with larger numbers. Is there an easier way to go about this? (define b 3) (define z 0) (define divides? (lambda (a b) (= (remainder a b) 0))) (define (prime? n) (cond ((or (= n 1) (= n 0)) false) (

Racket: execute file and stay in interactive mode

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 05:22:31
Is there a way from a command line to run Racket file and stay in the interactive mode afterwards? E.g. same in Python it would be: python -i <file.py> Assuming a foo.rkt that's this: #lang racket (provide x) (define x 42) (define y 4242) Then you can use -i to specify interactive mode (= REPL), together with -t to require the file: $ racket -it foo.rkt Welcome to Racket vX.X.X. > x 42 > y y: undefined; ... > (exit) Note that y is not bound since it's in the module and not provided out. More likely you want a REPL that is "inside" the foo module, which can be done using enter! to go into the