How is set! defined in scheme?

后端 未结 6 1164
囚心锁ツ
囚心锁ツ 2020-12-20 05:45

How would you implement your own set! function in Scheme? A set! function is a destructive procedure that changes a value that is defined taking into account th

6条回答
  •  甜味超标
    2020-12-20 06:35

    Can't, can't, can't. Everyone is so negative! You can definitely do this in Racket. All you need to do is to define your own "lambda" macro, that introduces mutable cells in place of all arguments, and introduces identifier macros for all of those arguments, so that when they're used as regular varrefs they work correctly. And a set! macro that prevents the expansion of those identifier macros, so that they can be mutated.

    Piece of cake!

提交回复
热议问题