scheme

Error setting load-noisily? and auto-exiting in MIT-Scheme

自作多情 提交于 2019-12-06 08:46:24
In order to debug MIT-Scheme scripts with Vim, I want to be able to run the script file currently being edited as conveniently as possible. Here is what I'm doing: sicp.scm (set! load-noisily? #t) (define (abs x) (cond ((> x 0) x) ((= x 0) 0) ((< x 0) (- x)) ) ) (abs 42) (abs -24) (exit) After executing :!mit-scheme --eval "(load \"sicp\")" when editing sicp.scm in Vim, I get: Image saved on Saturday May 17, 2014 at 2:39:25 AM Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 Edwin 3.116 ;Loading "sicp.scm"... Kill Scheme (y or n)? There are two main issues: The

Changing a function into CPS style

南楼画角 提交于 2019-12-06 08:33:19
问题 We were asked to write a procedure that when given a list it will replace the first occurrence of a given element and only the first, but the catch is to write in CPS style. We are unable to turn it to CPS style written procedure that is given a success-cont and fail-cont.. If anyone is willing to give it a try we will really appreciate it :] The procedure we have (graciously provided by answers here): (define (replace-one list old new) (cond ((pair? list) (let ((next (replace-one (car list)

Iterate through the letters of the alphabet in Racket

纵饮孤独 提交于 2019-12-06 07:09:43
问题 I'd like to write a program that iterates through the letters in the alphabet as symbols and does something with them. I'd like it to be roughly equivalent to this C code: for(char letter = 'a'; letter <= 'z'; letter++) { printf("The letter is %c\n", letter); } I really have no idea how to do this in Racket. Thanks for your help. 回答1: Assuming that you only want to iterate over lowercase English alphabet letters, here's one way to do it: (define alphabet (string->list

How to show different content based on the path in Racket web servlets?

天涯浪子 提交于 2019-12-06 06:04:22
问题 I'm trying to follow the tutorial on the Racket guide on simple web apps, but can't get one, basic, basic thing. How can you have a servlet serve different content based on the request URL? Despite my scouring, even the huge blog example was one big file and everything handled with huge get query strings behind my back. How can I do anything based on URLs? Clojure's Noir framework puts this basic feature big up front on the home page ( defpage ) but how to do this with Racket? 回答1: The URL is

creating permutation of a list in scheme

三世轮回 提交于 2019-12-06 05:35:31
问题 I'm trying to write a function that creates the permutation of a list using just the basic list constructs (cons, empty, first, rest). I'm thinking of inserting the first value of the list everywhere in the recursive call of the rest of the list, but I'm having some trouble with my base case. My code: (define (permutation lst) (cond [(empty? lst) (cons empty empty)] [else (insert_everywhere (first lst) (permutation (rest lst)))])) (permutation (list 1 2)) gives me (list 1 2 empty 2 1 empty).

Multiple lines comments in Scheme (RnRS)

独自空忆成欢 提交于 2019-12-06 05:31:45
问题 I created this solution: ; use like this: ; (/* content ... */ <default-return>) ; or ; (/* content ... */) => #f (define-syntax /* (syntax-rules (*/) ((/* body ... */) #f) ((/* body ... */ r) r))) But is it really the best or easiest way? 回答1: You can't do it this way -- it won't work for a number of contexts. Here are some examples that won't work: (+ (/* foo */) 1 2) (define (foo a (/* b */) c) ...) (/* foo; bar */) (/*x*/) (let ((x (/* 1 */) 2)) ...) (let ((/* (x 1) */) (x 2)) ...) (car '

ANTLR grammar for scheme R5RS

你说的曾经没有我的故事 提交于 2019-12-06 05:09:31
I'm beginner in ANTLR and I'm learning it by an example. I use C as my target language. The example is a Scheme R5RS grammar file taken from this question , with a little modification(rename the grammar name and add some options with the grammar specification untouched). antlr generated the lexer and parser, and I compile it with a test main() in which I just do some initialization and simply call the parser. When runing the test program with a piece of scheme code, the parser detect some syntax error(which should not happen!) main function in test.c #include <stdio.h> #include "r5rsLexer.h"

Bubble Sorting in Scheme

穿精又带淫゛_ 提交于 2019-12-06 04:30:37
问题 I am writing a recursive code to Bubble Sort (smallest to largest by swapping) I have a code to do the bubble sort just once (define (bubble-up L) (if (null? (cdr L)) L (if (< (car L) (cadr L)) (cons (car L) (bubble-up (cdr L))) (cons (cadr L) (bubble-up (cons (car L) (cddr L)))) ) ) if i put a list into this code, it returns the list with the largest number at the end EX.. (bubble-up ' (8 9 4 2 6 7)) -> ' (8 4 2 6 7 9) Now i am trying to write a code to do the (bubble-up L) N times (the

Applying A List of Functions to a Number

▼魔方 西西 提交于 2019-12-06 03:57:02
问题 I understand that functions in Scheme/Racket like map, foldr, and filter, can do wonderful things like apply a function to a list of elements. Is it possible to apply a list of functions to a single element? I would like to generate the values produced by each of the functions, then find their maximum. Thank you. 回答1: For the first part, this procedure will apply a list of functions to a single argument, assuming that all the functions receive only one argument. A list with the results is

DrRacket EOPL Scheme output

给你一囗甜甜゛ 提交于 2019-12-06 03:51:49
I am working through the EOPL Scheme exercises using DrRacket in Windows 7. When I switch from #lang racket to #lang eopl, the output from the definitions pane no longer shows up in the interaction pane. To be clear, as trivial example, running #lang racket 4 produces 4 > as you would expect. But running #lang eopl 4 produces only > Is there anything I can do to change this behavior or is there another pane I should be looking at for output? I can, of course, evaluate expressions in the interaction pane and see the output, but this is tedious when I have multiple expressions I want to evaluate