scheme

How to explain scheme expression '(a 'b)

纵然是瞬间 提交于 2019-12-24 04:56:15
问题 '(a 'b) gives out the answer (a 'b). How does this work when there is no binding for a (which is unquoted). 回答1: This is what happens when we evaluate the expression: '(a 'b) => (a 'b) The ' quote is shorthand for the quote special form, see the linked documentation for more details: (quote (a 'b)) => (a 'b) As you can see, it prevents the quoted arguments from being evaluated, so it doesn't matter if a is undefined, because a is not interpreted as a variable inside a quoted expression. It's

Scheme: overload built-in procedures, general overloading

浪尽此生 提交于 2019-12-24 04:06:06
问题 More specifically, can you overload the built-in Scheme procedure display? More generally, how can you overload any procedure in Scheme? 回答1: Scheme doesn't have overloading based on types a`la Java/C++, it's dynamically typed so it wouldn't make sense. You can do a few things though: You can overload based on the structure of the arguments: (define overload1 (case-lambda ((x y) (+ x y)) ((x y z) (+ (- x y) z)))) This doesn't really help you though since display is only going to take one

Compare two lists and return false if they are not equal scheme

被刻印的时光 ゝ 提交于 2019-12-24 03:39:27
问题 i would like to ask you for help to complete code below with condition which is testing if lists ws and vs are not equal. If they are not equal so return text false(#f) else process code below. I stared with fulfilling variables len1 and len2 which are counting length of both lists. When i run it i am getting this error: lambda: no expression after a sequence of internal definitions in: lambda What i am doing wrong? (define (weighted-sum . ws) (define (sub . vs) (let ((len1 (length ws)) (len2

using stop-when in racket

泪湿孤枕 提交于 2019-12-24 03:35:12
问题 I've been messing around with this program. It takes a number and adds 1 to it. I am wondering how exactly could you use stop-when here? For example, to make it stop at 5? I suppose a cond statement is necessary here. Thanks. (require 2htdp/image) (require 2htdp/universe) (define (my-tick n) (add1 n)) (define (my-render n) (text (number->string n) 36 "silver")) (big-bang 1 (on-tick my-tick 2) (to-draw my-render)) 回答1: Give stop-when a predicate that consumes a world and returns true or false.

Scheme and Shallow Binding

天大地大妈咪最大 提交于 2019-12-24 03:07:33
问题 (define make (lambda (x) (lambda (y) (cons x (list y))))) (let ((x 7) (p (make 4))) (cons x (p 0))) I'm new to Scheme and functional program, so I am a bit clunky with walking through programs, but I get that if I used deep binding this program will return (7 4 0). Makes sense. What would this program do using shallow binding? I get this may sound dumb but is the p in the line with cons a redefinition? So in that case, we would return (7 0)? Basically, I understand the concept of deep v.

Intersect more lists in Scheme

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:14:14
问题 I am trying to intersect more lists in Scheme and I need a little help. The lists look like this: The first two: (((?x john) (?city new-york)) ((?x mike) (?city chicago)) ((?x mary) (?city london))) and (((?city chicago)) ((?city new-york))) I need to look in every list (say A) from the first list and see if there is a list (say B) in the second one so that A has at least one element in common with B. If there is no such element, the resulting list will not contain A. The result for the two

(Racket/Scheme) Subtraction yields result off by incredibly small margin

喜你入骨 提交于 2019-12-24 02:07:48
问题 I'm currently messing around with "How To Design Programs" - using Scheme/Racket; I've come across a really peculiar feature in the R5RS version of Scheme. When conducting a simple subtraction, albeit using values with decimal point accurace, answers are minutely off what would be expected. For example; given the following subtraction operation: (- 5.00 4.90) => 0.09999999999999965 When one should surely be expecting a clean 0.10? Whole number subtraction works as expected; > (- 5 4) => 1 > (

redirect browser in SimpleHTTPServer.py?

ε祈祈猫儿з 提交于 2019-12-24 02:05:02
问题 I am partially through implementing the functionality of SimpleHTTPServer.py in Scheme. I am having some good fun with HTTP request/response mechanism. While going through the above file, I came across this- " # redirect browser - doing basically what apache does" in the code". Why is this redirection necessary in such a scenario? 回答1: Imagine you serve a page http://mydomain.com/bla that contains <a href="more.html">Read more...</a> On click, the user's browser would retrieve http://mydomain

Racket - implementing the let* function using macro

﹥>﹥吖頭↗ 提交于 2019-12-24 01:54:54
问题 I need to implement my_let* using defmacro which works similarly to let*, but while let* is expanded to a series of nested let calls (behind the scenes), my_let* needs to be expanded to a single let call, and use the define statement to define the arguments i get. an example of using my_let*: (my_let* ((a 2) (b 3) (c (+ a b))) (+ a b c)) and the return value of this code should be 10. just as if it was use let*. the code above will be expanded in my_let* to the following: (let () (define a 2)

Executing generated assembler inline

江枫思渺然 提交于 2019-12-24 01:23:52
问题 I was reading the following presentation: http://wingolog.org/pub/qc-2012-js-slides.pdf which talks about (4,10,19) inline ASM generation as a technique used in Javascript optimisation. In the following paper: https://sites.google.com/site/juliangamble/Home/Compilers%20Tutorial%202006-09-16.pdf?attredirects=0&d=1 at page 30 and 31 they talk about using scheme to generate ASM that is subsequently linked and executed in a subsequent OS process. What about the scenario where you want to generate