PasteRack.org
Paste # 8451
2018-08-03 08:38:10

Fork as a new paste.

Paste viewed 455 times.


Embed:

  1. #lang racket
  2.  
  3. ; This code is not supposed to work just to show the intention of the function
  4. ; Still need to learn how to do contracts, but basically
  5. ; output-variables has to be a list of symbols
  6. ; and a and b numbers
  7. (define (model par-a par-b output-variables)
  8.   (letrec
  9.       ((c (* par-a par-b))
  10.        (d (/ par-a par-b))
  11.        (x (+ c 1))
  12.        (y (+ d 1)))
  13.     (for/list ([var output-variables])
  14.       ; instead of void add something that would
  15.       ; restrict namespace to variables defined in letrec
  16.       (define ns void)
  17.       (eval var) ns)
  18.     ))
  19.  
  20. ; This would be ok
  21. (model 10 10 '(c d)) ; ==> (100 1)
  22.  
  23. ; This would give an error
  24. (model 10 10 '(c pi)) ; undefined error

=>

c: undefined;

 cannot reference an identifier before its definition

  in module: 'm

c: undefined;

 cannot reference an identifier before its definition

  in module: 'm