scheme

Python Macros: Use Cases?

筅森魡賤 提交于 2019-12-04 07:44:08
问题 If Python had a macro facility similar to Lisp/Scheme (something like MetaPython), how would you use it? If you are a Lisp/Scheme programmer, what sorts of things do you use macros for (other than things that have a clear syntactic parallel in Python such as a while loop)? 回答1: Some examples of lisp macros: ITERATE which is a funny and extensible loop facility CL-YACC/FUCC that are parser generators that generate parsers at compile time CL-WHO which allows specifying html documents with

Using “do” in Scheme

雨燕双飞 提交于 2019-12-04 07:39:35
What is the difference between CODE SNIPPET 1 and CODE SNIPPET 2? ;CODE SNIPPET 1 (define i 0) (do () ((= i 5)) ; Two sets of parentheses (display i) (set! i (+ i 1))) ;CODE SNIPPET 2 (define i 0) (do () (= i 5) ; One set of parentheses (display i) (set! i (+ i 1))) The first code snippet produces 01234 and the second produces 5. What is going on? What does the extra set of parentheses do? Also, I have seen [(= i 50)] used instead of ((= i 5)) . Is there a distinction? Thanks! Jörn Horstmann The general structure of a do form is like this: (do ((<variable1> <init1> <step1>) ...) (<test>

What is the best Scheme interpreter or compiler? [closed]

人走茶凉 提交于 2019-12-04 07:33:46
问题 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 6 years ago . Hey everyone, I want to start using Scheme and I have two questions. First, would you recommend using an interpreter or a compiler for

Is IronScheme interpreted or compiled? Does it benefit from .NET Framework optimizations?

此生再无相见时 提交于 2019-12-04 07:22:43
In the book "IronPython in Action," the author states that IronPython, unlike CPython, benefits from certain optimizations, both in the JIT and in the framework itself, that CPython cannot take advantage of. Consequently, IronPython is potentially faster than CPython is, especially for multithreading scenarios. Does IronScheme benefit from such optimizations? Is it an interpreter (not a compiler), and is it an interpreter because that's the nature of Lisp, that it must be interpreted to provide the Lisp-like flexibility? If it is an interpreter, can it still benefit from optimizations in the

How can I do web programming with Lisp or Scheme?

不打扰是莪最后的温柔 提交于 2019-12-04 07:22:06
问题 I usually write web apps in PHP, Ruby or Perl. I am starting the study of Scheme and I want to try some web project with this language. But I can't find what is the best environment for this. I am looking for the following features: A simple way of get the request parameters (something like: get-get #key, get-post #key, get-cookie #key). Mysql access. HTML Form generators, processing, validators, etc. Helpers for filter user input data (something like htmlentities, escape variables for put in

How write a function that returns a list of 'n' functions based on an input

China☆狼群 提交于 2019-12-04 06:46:53
问题 I'm looking to create a function that returns a list of 'n' functions each of which increments the input by 1, 2, 3... n respectively. I use DrRacket to try this out. A sample of expected outcome : > (map (lambda (f) (f 20)) (func-list 5)) (21 22 23 24 25) I'm able to write this down in a static-way : > (define (func-list num) > (list (lambda (x) (+ x 1)) (lambda (x) (+ x 2)) (lambda (x) (+ x 3)) (lambda (x) (+ x 4)) (lambda (x) (+ x 5))) [Edit] Also that a few restrictions are placed on

Scheme removing nested duplicates

霸气de小男生 提交于 2019-12-04 06:36:17
问题 So I'm programming in scheme and made a function that removes duplicated but it doesn't work for nested. I can't really figure out a good way to do this, is there a way to modify the current code I have and simply make it work with nested? lists? Here's my code (define (duplicates L) (cond ((null? L) '()) ((member (car L) (cdr L)) (duplicates (cdr L))) (else (cons (car L) (duplicates (cdr L)))))) 回答1: So your procedure jumps over elements that exist in the rest of the list so that (duplicates

How does `let` work in Scheme?

[亡魂溺海] 提交于 2019-12-04 06:22:31
I use let to create a temporary variable, and then use this temporary variable in the next statement. However, DrScheme complained, let: bad syntax (not an identifier and expression for a binding) in: temp This is my code snippet: (define (case-one-helper str) (let (temp (substring str (+ 3 (string-contains str "my")))) (substring temp (string-contains temp " ")))) I wonder if the value of variable created by let has to be known at compiled time? Edit I've just figured out, missing () . Thanks, Jason While not exactly the problem you're experiencing, but an aside based on your questioning

Scheme run length encoding

◇◆丶佛笑我妖孽 提交于 2019-12-04 05:56:00
问题 The problem is to: Write a function (encode L) that takes a list of atoms L and run-length encodes the list such that the output is a list of pairs of the form (value length) where the first element is a value and the second is the number of times that value occurs in the list being encoded. For example: (encode '(1 1 2 4 4 8 8 8)) ---> '((1 2) (2 1) (4 2) (8 3)) This is the code I have so far: (define (encode lst) (cond ((null? lst) '()) (else ((append (list (car lst) (count lst 1)) (encode

(define (average …)) in Lisp

蓝咒 提交于 2019-12-04 05:50:40
I'm just playing around with scheme/lisp and was thinking about how I would right my own definition of average . I'm not sure how to do some things that I think are required though. define a procedure that takes an arbitrary number of arguments count those arguments pass the argument list to (+) to sum them together Does someone have an example of defining average ? I don't seem to know enough about LISP to form a web search that gets back the results I'm looking for. The definition would be a very simple one-liner, but without spoiling it, you should look into: a "rest" argument -- this