racket

How do I get a definition's name as a symbol?

余生长醉 提交于 2021-02-19 08:18:09
问题 How do I get a definition's name as a symbol in Scheme and/or Racket? Suppose I have these definitions: (define bananas 123) (define multiply *) (define (pythagoras a b) (sqrt (+ (* a a) (* b b)))) How can I define def->symbol where: (def->symbol bananas) returns 'bananas (def->symbol multiply) returns 'multiply (def->symbol pythagoras) returns 'pythagoras Is this a case where I have no choice but to learn and use these advanced things called "macros"? 回答1: Just as you suspect, we need to use

Is there a way to see the body of a lambda in Racket?

谁说胖子不能爱 提交于 2021-02-19 04:46:14
问题 Say I have this code: #lang racket (define a ((λ (x) x) ((λ (y) y) (λ (z) ((λ (w) w) z))))) I know intuitively that this lambda expression is (extensionally) equal to (λ (z) z) My question is if there is a way to print out the body of a in case I want to see how much the function got simplified internally by Racket. More information: By default, if I type a into the interpreter, I get #<procedure:y> (This seems to give a hint as to how much evaluation happened). I can change the output style

DrRacket, R5RS and the error procedure

不想你离开。 提交于 2021-02-19 03:50:05
问题 I love DrRacket IDE, but currently I'm building a pet project where I would like to be independent from it, meaning i'm commited to use only R5RS standard procedures. The thing is, in DrRacket there's this procedure called "error" which i would like to continue using but I can't find it in the Standards. What i would like to know is if there's a way to emulate that "error" procedure using only the Standards procedures so that the code is portable between different implementations of Scheme. I

Dr Racket, R5RS and SRFI

只谈情不闲聊 提交于 2021-02-11 01:15:17
问题 Whenever I try to use srfi/1 functions like fold and reduce in drracket r5rs language I get an null-list? error. After some research I found that it is due to the fact that the function requires and immutable list but gets a mutable one. How do I create immutable list in r5rs or is this srfi/1 not designed with r5rs in mind? 回答1: This is basically reiterating what John said, but it definitely does merit a full answer status. (John, I'll be happy to delete this if you copy this answer verbatim

how to make HTML from a list in scheme, racket

北城以北 提交于 2021-02-10 06:48:33
问题 This is a very long question ... I am new and joined, so please don't attack me. Apologies for my bad communications in English. I have some defintions: An HTML(H) is one of Str Tag A Tag is (cons Sym (listof H)) I want to use mutual recursion,make the HTML into real HTML code. For example, (list 'html (list 'head (list 'title "Hi")) (list 'body (list 'h1 "Welcome") "Text")) Turns into: "<html><head><title>Hi</title></head><body><h1>Welcome</h1>Text</body></html>" This should work for any

miniKanren: How to define #s and #u?

我的未来我决定 提交于 2021-02-10 00:23:53
问题 In miniKanren, succeed can be defined as (define succeed (== #t #t)) , and fail can be defined as (define fail (=== #t #f)) . But what about #s and #u as short forms of succeed and fail , as they appear in The Reasoned Schemer ? (define #s succeed) produces an error in Racket: Welcome to Racket v7.2. > (require Racket-miniKanren/miniKanren/mk) > (define #s succeed) ; readline-input:2:8: read-syntax: expected `(`, `[`, or `{` after `#s` [,bt ; for context] #<procedure:...iniKanren/mk.rkt:337:4

miniKanren: How to define #s and #u?

≯℡__Kan透↙ 提交于 2021-02-10 00:20:46
问题 In miniKanren, succeed can be defined as (define succeed (== #t #t)) , and fail can be defined as (define fail (=== #t #f)) . But what about #s and #u as short forms of succeed and fail , as they appear in The Reasoned Schemer ? (define #s succeed) produces an error in Racket: Welcome to Racket v7.2. > (require Racket-miniKanren/miniKanren/mk) > (define #s succeed) ; readline-input:2:8: read-syntax: expected `(`, `[`, or `{` after `#s` [,bt ; for context] #<procedure:...iniKanren/mk.rkt:337:4

miniKanren: How to define #s and #u?

橙三吉。 提交于 2021-02-10 00:20:36
问题 In miniKanren, succeed can be defined as (define succeed (== #t #t)) , and fail can be defined as (define fail (=== #t #f)) . But what about #s and #u as short forms of succeed and fail , as they appear in The Reasoned Schemer ? (define #s succeed) produces an error in Racket: Welcome to Racket v7.2. > (require Racket-miniKanren/miniKanren/mk) > (define #s succeed) ; readline-input:2:8: read-syntax: expected `(`, `[`, or `{` after `#s` [,bt ; for context] #<procedure:...iniKanren/mk.rkt:337:4

miniKanren: How to define #s and #u?

谁说胖子不能爱 提交于 2021-02-10 00:20:32
问题 In miniKanren, succeed can be defined as (define succeed (== #t #t)) , and fail can be defined as (define fail (=== #t #f)) . But what about #s and #u as short forms of succeed and fail , as they appear in The Reasoned Schemer ? (define #s succeed) produces an error in Racket: Welcome to Racket v7.2. > (require Racket-miniKanren/miniKanren/mk) > (define #s succeed) ; readline-input:2:8: read-syntax: expected `(`, `[`, or `{` after `#s` [,bt ; for context] #<procedure:...iniKanren/mk.rkt:337:4

miniKanren: How to define #s and #u?

試著忘記壹切 提交于 2021-02-10 00:19:56
问题 In miniKanren, succeed can be defined as (define succeed (== #t #t)) , and fail can be defined as (define fail (=== #t #f)) . But what about #s and #u as short forms of succeed and fail , as they appear in The Reasoned Schemer ? (define #s succeed) produces an error in Racket: Welcome to Racket v7.2. > (require Racket-miniKanren/miniKanren/mk) > (define #s succeed) ; readline-input:2:8: read-syntax: expected `(`, `[`, or `{` after `#s` [,bt ; for context] #<procedure:...iniKanren/mk.rkt:337:4