user1732445
user1732445

Reputation: 235

List operation in Racket

Is there list operation such like

'(x y) '(1 2)

(substitution '(x y) '(1 2) (+ 'x 'y))

-> (each symbol relatively matched by number list, and substituted)

-> (x = 1, y = 2)

-> (+ 1 2)

-> 3

I cannot find any idea from reference.

http://docs.racket-lang.org/reference/pairs.html

Upvotes: 0

Views: 145

Answers (2)

dyoo
dyoo

Reputation: 12033

If you are trying to represent a mapping between names and values (a "dictionary"), there are several ways to do it. Racket provides a hash type that can associate names to values. You can read about them in the Guide. There is a more generic approach to use dictionary-like values in Racket (described in the racket/dict library) that works across different data types, and not just hashes alone.

Upvotes: 1

C. K. Young
C. K. Young

Reputation: 223193

You can use let:

(let ((x 1)
      (y 2))
  (+ x y))

Upvotes: 1

Related Questions