scheme

Scheme symbolic equivalence

Hi all. The platform i'm working with is DrScheme. I've seen that a pair (a b) [constructed by (cons a b)] is implemented within the language like a procedure that looks like this: (define (cons a b) (lambda(pick) (cond ((= pick 1) a) ((= pick 2) b)))) and the selectors: (define (car x) (x 1)) (define (cdr x) (x 2))...

Calculate Sums with accumulate

procedure accumulate is defined like this: (define (accumulate combiner null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulate combiner null-value term (next a) next b)))) problem 1: x^n ;Solution: recursive without accumulate (define (expon x n) (if (> n 0) (* x (ex...

Unable to use bigloo scheme FFI's through eclipse to open and read from a file.

I am trying to port Bigloo scheme functions through Eclipse. My current task is to write a java class in eclipse which will call a bigloo scheme function defined in a .scm file. This scm file has been already compiled to a class and included as a library. The problem is when I am trying to open the file using the bigloo function "open-i...

Unable to use Bigloo function "open-input-port" through Eclipse.

Hello, I use the Bigloo 3.3a version. I am currently working on running Bigloo scheme functions (compiled into .class) from Eclipse by calling the functions from a java class. I follow the following steps: Take a .scm file with possibly several functions defined in it. populate it into a package structure. Compile these files into eit...

Why won't `let` work for naming internal recursive procedures?

Consider the following implementation of a function to compute factorial: [1] (define fac-tail (lambda (n) (define fac-tail-helper (lambda (n ac) (if (= 0 n) ac (fac-tail-helper (- n 1) (* n ac))))) (fac-tail-helper n 1))) I attempted to rewrite using let for the inner define: (define f...

CAR and CDR of a list in Scheme

Hi all, I am confused as to how car and cdr work on lists. Here is an example of what I have tried: (define sample (read)) (display sample) (display (car sample)) (display (cdr sample)) (display (car (cadr sample))) (display (cdr (cdr sample))) On entering the value '(A B C D E F), here is what I get: '(a b c d e f) quote ((a b c d...

Adding an element to List in Scheme

Hi All, Below is my code which takes a car element of a list(carVal) and an list(initialized to empty) as parameters. I want to append the element to the list but the same is not working. (define populateValues (lambda (carVal currVal) (append currVal(list carVal )) (display currVal))) The display shows empty list all...

Overhead of call-by-need / call-by-name Lisp interpreter strategy

I've a partially finished interpreter for a lexically scoped 'pure Lisp' (no set!) that uses a call-by-need evaluation model which comes down to call-by-name with simple caching, the interpreter naturally uses an environment-based evaluation model. The standard way of evaluating lambda abstractions, as in, constructing a new environment...

Getting a line of user input in Scheme?

I know you can use (read) to get a user-inputted expression, but (read) will only get the first expression, evaluating anything afterwards. I was wondering if there was any way I could read an entire line of user input, perhaps turning said line into a list? (let ((input (read-user-line))) ;; user could type "cons 2 3" without quotes...

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

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 ...

PLT[Racket/Scheme] Compound Interest + Accumulators -How to....

Hi (geek) folks, I'm fiddling another time with a (should be easy) task. compound interest... (formula is known) Scheme... (For one single years everything works flawlessy) Problem: Accumulator needed... My program has to be able to remember the result of the former calculation and put it as a blueprint for the next one following. He...

Using "and" in Scheme

Hey, I'm trying to use and in a cond statement. Basically, instead of simply checking that <exp1> is true before running some code, I need Scheme to check that <exp1> AND <exp2> are true. I understand that (and #t #f) evaluates to #f and that (and (= 10 (* 2 5)) #t) evaluates to #t. Unfortunately, Scheme will not accept (and (eqv? (len...

Using "do" in Scheme

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 () ...

Is there a Scheme interpreter that uses Normal-order evaluation?

I've been slowly working my way though the exercises in Structure and Interpretation of Computer Programs. Section 1.1.5 talks about applicative vs. normal-order evaluation, and the topic has come up several times in the text afterward. Since the interpreter uses applicative-order evaluation, it's easy to just insert display debug stat...

In Scheme the purpose of (let ((cdr cdr)) ...

I've been studying Scheme recently and come across a function that is defined in the following way: (define remove! (let ((null? null?) (cdr cdr) (eq? eq?)) (lambda ... function that uses null?, cdr, eq? ...) What is the purpose of binding null? to null? or cdr to cdr, when these are built in functions th...

How to make just part of a macro hygienic

I'd like to have a version of lambda, called lambda-r, from within which you can return. An example: (+ ((lambda-r () (return 1) 2)) 5) This would give the value 6. Although you might expect the value to be 7, it's 6 because 1 is returned from the lambda-expression before 2 is reached. Here's an example of the kind of transfo...

Proper commenting for functional programming

I've been learning scheme, and I just realized that I don't really know how to properly comment my functional scheme code. I know how to add a comment of course - you add a ; and put your comment after it. My question is what should I put in my comments, and where should I comment for maximum readability and comprehensability for other p...

Achieving variables in the local syntax in the Scheme environment

How we can achieve variables that we defined in the (local ...) syntax in Scheme? For example in this code below, (define (erkan x) (local ((define y 10)) (* x y))) how can I directly get the value of y ? ...

(define (average ....)) in Lisp

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...

What do I need to do to get paid to Scheme?

I'm a big fan of functional programming in general, Schemes in particular, and PLT-Racket ideally. I am wondering what concrete steps are likely to get me into a position where coding Scheme (or some functional language) is the bulk of the work. I'm actually quite interested in academia, but on the other hand, I don't feel like I neces...