scheme

'(quote quote) in scheme

孤人 提交于 2019-12-20 02:12:58
问题 I'm trying to learn scheme by myself. Could anyone tell me why '(quote quote) will output 'quote , and '(quote 'quote) will output ''quote ? Thank you very much! 回答1: This expression: '(quote quote) ... after expanding '<something> to (quote <something>) is equivalent to (quote (quote quote)) , notice that the symbol quote is being quoted two times, and this expression is evaluated and printed as ''quote . On the other hand, this expression: '(quote 'quote) ... is equivalent to (quote (quote

Reverse a list in Scheme with foldl and foldr

浪子不回头ぞ 提交于 2019-12-20 01:34:43
问题 How can you define a function to reverse a list in Scheme by using foldr and foldl ? What we want is a succinct solution to reverse a list in Scheme using a foldl call and a different solution using a foldr call, as defined: (define (foldl operation lst initial) (if (null? lst) initial (foldl operation (cdr lst) (operation (car lst) initial)))) and (define (foldr operation lst initial) (if (null? lst) initial (operation (car lst) (foldr operation (cdr lst) initial)))) The astute person will

Convert string to code in Scheme

会有一股神秘感。 提交于 2019-12-19 17:44:14
问题 How do I convert a string into the corresponding code in PLT Scheme (which does not contain the string->input-port method)? For example, I want to convert this string: "(1 (0) 1 (0) 0)" into this list: '(1 (0) 1 (0) 0) Is it possible to do this without opening a file? 回答1: Scheme has procedure read for reading s-expressions from input port and you can convert a string to input stream with string->input-port . So, you can read a Scheme object from a string with (read (string->input-port "(1 (0

Overlapping module imports in Racket

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 16:55:26
问题 I want to load an image and animate it in Racket. I can do it easily in the Dr. Racket, but I am using Emacs with Geiser. To load the image I need to: (require racket/draw) Next, to draw this image onto the screen, I'm planning to use the big-bang module. To load this module I have to: (require 2thdp/image) But I get this error: module: identifier already imported from: 2htdp/image at: make-pen in: racket/draw errortrace...: This basically means that I can't import the same module twice. But

How can I create an association list from 2 lists?

若如初见. 提交于 2019-12-19 09:05:42
问题 In DrScheme, how can I create an association list from 2 lists? For example, I have, y = ( 1 2 3 ) x = ( a b c ) and I want z = ((a 1) (b 2) (c 3)) 回答1: Assuming Scheme (since your last 2 questions are on Scheme): (define x '(1 2 3)) (define y '(4 5 6)) (define (zip p q) (map list p q)) ;; <---- (display (zip x y)) ;; ((1 4) (2 5) (3 6)) Result: http://www.ideone.com/DPjeM 回答2: In C# 4.0 you can do it this way; var numbers = Enumerable.Range(1, 10).ToList<int>(); var abcs = new List<string>()

Scheme: Remove duplicated numbers from list

不打扰是莪最后的温柔 提交于 2019-12-19 08:16:10
问题 I wrote this code to create a list from en number of arguments given (define (create-list . e) e) But I need it to remove any duplicated numbers from the list within this block itself. I have tried and searched for hours and can't find a solution without placing dozens of lines of code on other blocks. For example let's say my input is (create-list . 2 2 3 5 5 ) I need the list created to be '(2 3 5) and not '(2 2 3 5 5 )... The order of the numbers doesn't matter. 回答1: Basically, you need to

reverse list - scheme

徘徊边缘 提交于 2019-12-19 07:55:35
问题 I'm trying to reverse a list, here's my code: (define (reverse list) (if (null? list) list (list (reverse (cdr list)) (car list)))) so if i enter (reverse '(1 2 3 4)), I want it to come out as (4 3 2 1), but right now it's not giving me that. What am I doing wrong and how can I fix it? 回答1: The natural way to recur over a list is not the best way to solve this problem. Using append , as suggested in the accepted answer pointed by @lancery, is not a good idea either - and anyway if you're

Capturing Macros in Scheme

我的梦境 提交于 2019-12-19 07:52:19
问题 What's the simplest way to define a capturing macro using define-syntax or define-syntax-rule in Racket? As a concrete example, here's the trivial aif in a CL-style macro system. (defmacro aif (test if-true &optional if-false) `(let ((it ,test)) (if it ,if-true ,if-false))) The idea is that it will be bound to the result of test in the if-true and if-false clauses. The naive transliteration (minus optional alternative) is (define-syntax-rule (aif test if-true if-false) (let ((it test)) (if it

How do I generate all permutations of certain size with repetitions in Scheme?

半腔热情 提交于 2019-12-19 07:04:26
问题 I am learning Scheme and I am trying to generate permutations with repetitions of certain size. For example, given n=4 and set S = {a, b, c, d, e, f}, I'd like to generate all possible permutations: {a,a,a,a},{a,a,a,b},...,{a,a,a,f},{a,a,b,a},{a,a,b,b},...,{a,a,b,f},...{f,a,a,a},{f,a,a,b}...,{f,a,a,f},...{f,f,f,f}. The trouble is that I can't understand how to pick 'a' 4 times, and remember that i had picked it 4 times, then pick 'a' 3 times, and 'b' one time, and remember all this, so I don

How to import .class file in a .java file?

本秂侑毒 提交于 2019-12-19 06:06:34
问题 What i need to do is as follows: I have a bigloo scheme program (*.scm), then using the bigloo frameworks jvm a class file is generated. I want to use this .class file from a .java file. That is, i need to import this(.class) file as i want to use some functions defined in the scheme file which is now a .class file. How do i do it in Eclipse? i have created two packages one for java and one for the .class file. Then i import the package containing the .class file. But i am not able to use the