Recurring with anonymous functions Common Lisp vs. Scheme

I'm working through the Little Schemer and I'm trying to convert all of the answers into Common Lisp. In chapter 8, anonymous functions are discussed, as well as returning anonymous functions. For example: (define insertL-f (lambda (test?) (lambda (n

Check the ascending order of a list in Racket

I'm new to racket and trying to write a function that checks if a list is in strictly ascending order. '( 1 2 3) would return true '(1 1 2) would return false (repeats) '(3 2 4) would return false My code so far is: Image of code (define (ascending?

Integer fraction numbers in the schema

Is there an easy way to display whole rational numbers for example: (average '(1 2 3 4)) ;returns 2 1/2 I would like it to return 5/2. Thank you.This is DrRacket-specific behavior. It customizes the Racket print handler to print out certain values in

How to use trigonometry in Scheme?

What are the names of the trigonometric functions in Scheme, and what units do they represent angles in?The Scheme standards define six trigonometric functions: sin, cos, tan, asin, acos, and atan. In particular, atan can be called with either 1 or 2

Access to the depth of the call stack in Scheme

In order to demonstrate the effectiveness of tail recursion, I would like a way to access the depth of the call stack dynamically in Scheme. Is there a way to do this? If not, is there a way to do this in other major functional languages (OCaml, Hask

Bigloo: Indicates the type of a function argument

Suppose I have a procedure called foo, which returns a ::float which is meant to take the following arguments: A procedure taking two ::float arguments. A ::float Another ::float How would I write an export for that function in the module part of the

How to convert the port to a chain and list in the racket?

How do I convert all chars of a port to a string or a list so that I can operate on it as either a list of chars or a string? I was wondering if something similar to (define (port->list port) (list port)) is possible.Racket provides a built-in port->

Diagram how to define var in so condition

I am newbie to Scheme programming and trying to define a var in if condition. For example, I have: (if (< x y) (define x y) ) ;(GOAL: if x < y, than x=y..) But I got the error: let: bad syntax (not an identifier and expression for a binding) in:...

Diagram of the sum of the test squares

I wrote a sum-of-squares function to test if a number n could be written as the sum of two squares. My code is as follows: (define (square x) (* x x)) (define (sum-of-squares n) (define (sum-of-squares-h k) (cond ((= k n) #f) ((= n (+ (square(floor(s

Recursive exponentiation racket programming

#lang eopl (define (expo base n ) (cond( (or (= base 1) (= n 0) ) 1) (else ( (* base (expo(base (- n 1))) ) ) ))) -> (enter! "expo.rkt") "expo.rkt"> (expo (2 1) ) ; application: not a procedure; ; expected a procedure that can be

What distinguishes a continuation of a function?

Continuation describes what happens next with some value, right? Isn't that just a function that takes a value and does some computation? (+ (* 2 3) 5) the continuation of (* 2 3) is (+ _ 5) (define k (lambda (v) (+ v 5))) What is the point of using

Scheme Tree Puzzle: Express an empty knot in a final pair

I am trying to solve a puzzle the crawls a binary tree in order to find if a specific value exists as a node. I am having an issue with evaluating a pair that looks like '(1 '()). I think when I evaluate (= 4 '()) it returns true which is incorrect o

binary trees seeking inside

Can anyone tell me what I need to do here? (define (count-values abst v) (cond [(empty? abst) 0] [else (+ (cond [(equal? v (bae-fn abst)) 1] (else 0)) (count-values .... v) (count-values .... v ))])) I basically need a function that counts the amount

Scheme Scoping (set and leave)

So I know that in Scheme define is for dynamic scoping and let for static scoping, yet the following thing confuses me: If I have (let ((x 0)) (define f (lambda () x)) (display (f)) (let ((x 1)) (display (f)) ) ) It will display 00. So far so good. H

How to decompose a list like this in scheme / lisp?

Input1: (decompose '(* 1 2 3 4)) Output1: '(* 1 (* 2 (* 3 4))) Input2 (decompose '(+ 1 2 3 (* 5 6 7))) Output2 '(+ 1 (+ 2 (+ 3 (* 5 (* 6 7))))) Does anyone have ideas about this?Same way as you would evaluate it, but instead of outputting the result,

the implementation of the binary search tree in the schema

Functions in scheme/racket. Working on a few functions using a binary search tree. I have already defined helper functions to be: ;; returns value of node (define (value node) (if (null? node) '() (car node))) ;; returns left subtree of node (define

Quotation detection function in schema code

I am trying to write a function that can check whether or not some input is a quotation for a syntax checker. I have the following code: (define is-quote-expression? (lambda (v) (equal? (car v) 'quote) (is-quotation? (cdr v))))) (define is-quotation?

Lisp / Scheme DSEL in C ++

I came across the following post on the boost mailing lists (emphasis mine): hello all, does anybody know of an existing spirit/lisp implimentation, and is there any interest in developing such a project in open source? None yet, AFAIK. I'll be writi

Simple recursion?

I'm new to programming and have had a hard time understanding recursion. There's a problem I've been working on but can't figure out. I really just don't understand how they are solvable. "Define a procedure plus that takes two non-negative integers

Saving the program image in the trick

I've heard that most lisps support saving image of running program into file. Does guile support this?I think that interoperating with other languages is pretty integral to what Guile is, and so there is a lot of state in an interpreter image that is

Common uses of letrec, named let and internal defines?

I have a couple of books on Scheme, and some of them mention named let and letrec, but none will actually give a convincing example of each (I mean, when and why would I use one instead of the other). Are there examples of situations where letrec/nam

Why is the Lisp community so fragmented?

To begin, not only are there two main dialects of the language (Common Lisp and Scheme), but each of the dialects has many individual implementations. For example, Chicken Scheme, Bigloo, etc... each with slight differences. From a modern point of vi

Running Scheme from the command line

How do you run Scheme programs from the terminal in linux(ubuntu)? Also how to accept arguments from the command-line in a Scheme program? Edit: Im using the DrScheme implementation.The DrScheme scheme implementation, and the name you use to execute

find the text of a procedure in the schema

The ipython python shell has a wonderful feature, whereby you can type: foo?? and see the text of function foo. Does scheme (in particular, MIT scheme), have anything like this? I want to be able to say (define (foo x) (* x x)) and later view (or eve

Why C # does not have lexically nested functions?

Why might the C# language designers not have included support for something like this (ported from Structure and Interpretation of Computer Programs, second ed., p. 30): /// <summary>Return the square root of x.</summary> double sqrt(double x)

Can someone help explain this diet procedure

Question: ((lambda (x y) (x y)) (lambda (x) (* x x)) (* 3 3)) This was #1 on the midterm, I put "81 9" he thought I forgot to cross one out lawl, so I cross out 81, and he goes aww. Anyways, I dont understand why it's 81. I understand why (lambd