racket

Use of lambda for cons/car/cdr definition in SICP

纵饮孤独 提交于 2019-11-26 06:40:25
问题 I was just beginning to feel I had a vague understanding of the use of lambda in racket and scheme when I came across the following \'alternate\' definitions for cons and car in SICP (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) For the life of me I just cannot parse them. Can anybody explain how to parse or expand these in a way that makes sense for total neophytes? 回答1: This is an interesting way to represent data: as

“application: not a procedure” in binary arithmetic procedures

五迷三道 提交于 2019-11-26 02:25:44
问题 I have a simple Racket definition for multiplying binary numbers together. It uses a well-tested \"addWithCarry\" definition that takes three parameters: two lists and a carry digit and returns the binary sum. The binary numbers are represented as lists in reverse order. I stepped through the test line with the debugger, and it goes through the recursion properly. It performs the multBins each time shrinking the y list as appropriate, then conducts the addWithCarry functions as expected. As

My code signals the error “application: not a procedure” or “call to non procedure”

眉间皱痕 提交于 2019-11-26 01:27:24
问题 During the execution of my code I get the following errors in the different Scheme implementations: Racket: application: not a procedure; expected a procedure that can be applied to arguments given: \'(1 2 3) arguments...: Ikarus: Unhandled exception Condition components: 1. &assertion 2. &who: apply 3. &message: \"not a procedure\" 4. &irritants: ((1 2 3)) Chicken: Error: call of non-procedure: (1 2 3) Gambit: *** ERROR IN (console)@2.1 -- Operator is not a PROCEDURE ((1 2 3) 4) MIT Scheme:

What is the difference between quote and list?

梦想与她 提交于 2019-11-26 00:25:42
问题 I know that you can use \' (aka quote ) to create a list, and I use this all the time, like this: > (car \'(1 2 3)) 1 But it doesn’t always work like I’d expect. For example, I tried to create a list of functions, like this, but it didn’t work: > (define math-fns \'(+ - * /)) > (map (lambda (fn) (fn 1)) math-fns) application: not a procedure; expected a procedure that can be applied to arguments given: \'+ When I use list , it works: > (define math-fns (list + - * /)) > (map (lambda (fn) (fn