scheme

running scheme from emacs

假装没事ソ 提交于 2019-12-18 03:21:10
问题 I'm a newbie to LISP. I am attempting to invoke the scheme interpreter from within emacs (version 23 running on windows). I loaded the xscheme library by telling emacs to M-x load-library and then entering xscheme at the prompt in the minibuffer. The library loaded, and then I issued the M-x run-scheme command. (I realize that all this loading can be done from .emacs at startup, but I am not concerned with that at the moment.) So far so good - the *scheme* buffer has been created, and now I'm

How do I define functions using Racket macros?

扶醉桌前 提交于 2019-12-18 02:54:39
问题 I am trying to write a macro that defines a special class of data structure with associated functions. I know this is possible; it is done multiple times in the core language itself. As a specific example, how would I define the define-struct macro in Scheme itself. It needs to create make-struct , struct-<<field>> , etc functions. I tried doing this using define , however, this only defines the function in the macro's lexical scope. How can I actually define a function in a macro? 回答1: The

Check if an argument is a list or an atom

狂风中的少年 提交于 2019-12-17 23:18:50
问题 How do I check if something is an atom? I'm looking for something like number? or list? . 回答1: Usually, you'll want to exclude the empty list too: (define (atom? x) (not (or (pair? x) (null? x)))) or, if you want to be more pedantic, then forbid vectors too: (define (atom? x) (not (or (pair? x) (null? x) (vector? x)))) And of course you can add much more here -- since it's marked as a racket question, you might want to add hash tables, structs, etc etc. So it can just as well be easier to

Get the points of intersection from 2 rectangles

夙愿已清 提交于 2019-12-17 21:56:11
问题 Let say that we have two rectangles, defined with their bottom-left and top-right corners. For example: rect1 (x1, y1)(x2, y2) and rect2 (x3, y3)(x4, y4) . I'm trying to find the coordinates(bottom-left and top-right) of the intersected rectangle. Any ideas, algorithm, pseudo code, would be greatly appreciated. p.s. I found similar questions but they check only if 2 rectangle intersect. 回答1: If the input rectangles are normalized, i.e. you already know that x1 < x2 , y1 < y2 (and the same for

Why is the Lisp community so fragmented? [closed]

不羁岁月 提交于 2019-12-17 21:43:15
问题 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 . To begin, not only are there two main dialects of the language (Common Lisp and Scheme), but each of the dialects has many individual

Fibonacci in Scheme

删除回忆录丶 提交于 2019-12-17 21:30:08
问题 I am trying to understand recursion in Scheme and I have a hard time doing the dry run for it, for example a simple Fibonacci number problem. Could someone break down the steps in which the additions take place, for me? (define (fib n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))) 回答1: If you're using Racket, as your tags indicate, then you have a built-in stepper. Enter the program into DrRacket, and click Step in the top-right menu: Then a stepper window will open up. Click Step over and

Understanding Deep Reverse

被刻印的时光 ゝ 提交于 2019-12-17 21:28:46
问题 Say I have the list '(1 2 3 (4 5 6) 7 8 9). It should return (9 8 7 (6 5 4) 3 2 1) using the following code below. I'm trying to understand how this iterative process works. Showing how this is done step by step would be very helpful. The part I get confused the most is when deep-reverse is called twice at this point (append (deep-reverse (cdr lst)) (list (deep-reverse (car lst))))) I don't know what happens then. (define (deep-reverse lst) (cond ((null? lst) '() ) ((pair? (car lst)) (append

How does the named let in the form of a loop work?

半腔热情 提交于 2019-12-17 20:19:03
问题 In an answer which explains how to convert a number to a list the number->list procedure is defined as follows: (define (number->list n) (let loop ((n n) (acc '())) (if (< n 10) (cons n acc) (loop (quotient n 10) (cons (remainder n 10) acc))))) Here a "named let" is used. I don't understand how this named let works. I see that a loop is defined where the variable n is equal to n , and the variable acc equal to the empty list. Then if n is smaller than 10 the n is consed to the acc. Otherwise,

Including an external file in racket

喜你入骨 提交于 2019-12-17 19:57:58
问题 I would like to include all the functions defined in a given racket file so that I get the same effect as if they were copied. Is it possible to do that? 回答1: You can use include as follows: Create a file called "foo.rkt" that looks like this: (define x 1) (define y 2) Then in another file: #lang racket (require racket/include) (include "foo.rkt") (+ x y) You should see the result 3 . You can see the documentation for include as well. 回答2: To export the functions out of a module, you use

How do I execute a .scm script (outside of the REPL) with MIT-Scheme?

ⅰ亾dé卋堺 提交于 2019-12-17 17:47:16
问题 I want to type something like 'scheme file.scm' and have it interpret the file, and then take me back to my shell, rather than loading it in the REPL. edit: I tried scheme < test.scm and it still uses the REPL, the only difference is that scheme exits when the stream ends. 回答1: scheme < file.scm should work (as long as you don't specify --interactive and stdin is not a terminal, scheme works non-interactively). 回答2: To run a scheme program using MIT Scheme: scheme --quiet < program.scm The -