scheme

How to start REPL for slimv with MIT-Scheme

半城伤御伤魂 提交于 2019-12-04 00:03:31
My operating system is Debian Squeeze. Here's the vim version: VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 12 2010 02:29:33) I read a tutorial on http://kovisoft.bitbucket.org/tutorial.html and tried to start REPL for MIT-Scheme. Unfortunately, I failed to start. When I pressed ",c", it started a terminal window loading mit-scheme. Nothing showed in the REPL buffer of vim. Some errors showed in the terminal: Listening on port: 4005 ;netcat: "4005: inverse host lookup failed: Unknown host" ;To continue, call RESTART with an option number: ; (RESTART 1) => Return to read-eval-print level 1.

find free variables in lambda expression

主宰稳场 提交于 2019-12-03 23:59:27
Does anyone know how I can figure out the free variables in a lambda expression? Free variables are the variables that aren't part of the lambda parameters. My current method (which is getting me nowhere) is to simply use car and cdr to go through the expression. My main problem is figuring out if a value is a variable or if it's one of the scheme primitives. Is there a way to test if something evaluates to one of scheme's built-in functions? For example: (is-scheme-primitive? 'and) ;Value: #t I'm using MIT scheme. [EDIT 4] Disclaimer; or, looking back a year later: This is actually a really

Is there a shorthand way to update a specific struct field in racket?

浪子不回头ぞ 提交于 2019-12-03 23:49:17
Suppose I have a struct with many fields: (struct my-struct (f1 f2 f3 f4)) If I am to return a new struct with f2 updated, I have to rephrase every other fields: (define s (my-struct 1 2 3 4)) (my-struct (my-struct-f1 s) (do-something-on (my-struct-f2 s)) (my-struct-f3 s) (my-struct-f4 s)) Which is redundant and would be a source of bugs if I update the number of the fields or changed their orders. I really wonder if there's a such way I can update a specific field for a struct like: (my-struct-f2-update (my-struct 1 2 3 4) (lambda (f2) (* f2 2))) ;; => (my-struct 1 4 3 4) Or I can just set

What are the benefits of letrec?

℡╲_俬逩灬. 提交于 2019-12-03 22:52:02
While reading "The Seasoned Schemer" I've begun to learn about letrec . I understand what it does (can be duplicated with a Y-Combinator) but the book is using it in lieu of recurring on the already define d function operating on arguments that remain static. An example of an old function using the define d function recurring on itself (nothing special): (define (substitute new old l) (cond ((null? l) '()) ((eq? (car l) old) (cons new (substitute new old (cdr l)))) (else (cons (car l) (substitute new old (cdr l)))))) Now for an example of that same function but using letrec : (define

Scheme - Map function for applying a function to elements in a nested list

99封情书 提交于 2019-12-03 21:38:49
I'm trying to write a mapping function in scheme that applies a function to each value in a nested list. For example, (map number? '(3 (2 A) 2 Z) should return (#t (#t #f) #t #f) Here's what I have so far: (define (map fun lst) (if (null? lst) '() (if (list? (car lst)) (cons (map fun (car lst)) (map fun (cdr lst))) (cons (fun (car lst)) (map fun (cdr lst)))))) It works if the nested list is at the front of the list. For example (map number? '((3 A) 2 Z)) correctly returns ((#t #f) #t #f) The problem occurs when the nested list occurs after another element in the original list. For example (map

How do I get the type of a value in Scheme?

帅比萌擦擦* 提交于 2019-12-03 20:40:52
问题 I want a function that gets the type of a value at runtime. Example use: (get-type a) where a has been define d to be some arbitrary Scheme value. How do I do this? Or do I have to implement this myself, using a cond stack of boolean? , number? etc. ? 回答1: In Scheme implementations with a Tiny-CLOS-like object system, you can just use class-of . Here's a sample session in Racket, using Swindle: $ racket -I swindle Welcome to Racket v5.2.1. -> (class-of 42) #<primitive-class:exact-integer> ->

Are there any purely functional Schemes or Lisps?

北城余情 提交于 2019-12-03 18:34:33
问题 I've played around with a few functional programming languages and really enjoy the s-expr syntax used by Lisps (Scheme in particular). I also see the advantages of working in a purely functional language. Therefore: Are there any purely functional Schemes (or Lisps in general)? 回答1: Probably not, at least not as anything other than toys/proofs of concept. Note that even Haskell isn't 100% purely functional--it has secret escape hatches, and anything in IO is only "pure" in some torturous,

Editing programs “while they are running”? Why?

有些话、适合烂在心里 提交于 2019-12-03 18:18:47
问题 I've been getting more into Lisp and Lispy languages lately, and I'm finding them quite powerful. One thing I've been reading all over the net is that a benefit of writing in Lisp, Clojure, etc, is that you can edit your program "while it's running". Perhaps I'm missing something, but what is the point? Sure, it might save a few seconds, but is that all? Whenever I make a change to my program I just stop it then start it again, and that has been working fine for decades. There must be a

Writing a Scheme interpreter with FPC: Recursive data structures

对着背影说爱祢 提交于 2019-12-03 17:33:53
Essentially, this is a question about recursive data structures in Pascal (FPC). As I would like to implement a Scheme interpreter like it is shown in SICP chapter 4, this question may be relevant for Schemers as well. :) S-expressions shall be represented as tagged data. So far, I have constructed a variant record, which represents numbers and pairs. Hopefully the code is readable and self-explanatory: program scheme; type TTag = (ScmFixnum, ScmPair); PScmObject = ^TScmObject; TScmObject = record case ScmObjectTag: TTag of ScmFixnum: (ScmObjectFixnum: integer); ScmPair: (ScmObjectCar,

Error with define in Racket

本小妞迷上赌 提交于 2019-12-03 17:15:38
问题 I just discovered Racket a few days ago, and I'm trying to get more comfortable with it by writing a little script that generates images to represent source code using #lang slideshow . I know that when programming in a functional paradigm it's good practice to create almost all your variables with let , but I find that it introduces too many levels of nesting and that Racket's let has an overcomplicated API which requires superfluous parentheses. I'm sure this is to remove ambiguity when