-1

I want to write a method that takes a literal, lets say

turn

end returns something like this

(my turn)

So, after that, if I call eval, scheme will call defined method my with parameter turn.

I did manage just to return some another literal or string, but I didn't manage to do what I wanted. And I didn't find any specification about something like this.

I assume I have somehow to use something like this: `(my,@param) but it doesn't work.

turn is a symbol

JohnDow
  • 1,242
  • 4
  • 22
  • 40
  • In Scheme, `my(turn)` is not a function application - the correct way is `(my turn)`. Another thing: what do you mean by `literal`? String? Variable? Symbol? – Benesh Mar 22 '14 at 12:39
  • 2
    +1 on the XY problem comment from @oscar-lopez . What larger problem are you trying to solve? – John Clements Mar 22 '14 at 16:50
  • It is not XY problem. I want to evaluate list of commands, and handle undefined literals using my own procedure. – JohnDow Mar 22 '14 at 17:44
  • 1
    I agree with Óscar and John Clements about the XY problem. Why are you attempting to "evaluate list of commands, and handle undefined literals using [your] own procedure"? There is a very high probability that there is a better way to solve that problem (the answer to the why). – C. K. Young Mar 22 '14 at 18:47

1 Answers1

1

Sounds like an XY problem to me, perhaps there's a simpler way to achieve what you really intend to do… Anyway, answering the question:

; we need to prevent the evaluation of the parameter,
; a normal procedure won't work here - we need a macro
(define-syntax method
  (syntax-rules ()
    ((_ x) '(my x))))

; sample input
(define turn 9)
(define (my param) (+ 1 param))

; setup the evaluation namespace
(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))

; first test: `method` returns a non-evaluated expression
(method turn)
=> '(my turn)

; second test: evaluate the returned expression
(eval (method turn) ns)
=> 10
Community
  • 1
  • 1
Óscar López
  • 232,561
  • 37
  • 312
  • 386