As far as I know, the book "Lisp In Small Pieces" should be a tremendous help for anyone who builds a Lisp interpreter or compiler. You might want to check it out.
On Mon, Aug 9, 2010 at 2:21 PM, CuppoJava <patrickli_2...@hotmail.com>wrote: > Thanks for the reply Jarkko. That helps quite a lot. I have some hacks > in place that works most of the time, but was stuck trying to figure > out a general solution. Knowing that there isn't one puts my mind at > ease. > -Patrick > > On Aug 9, 1:56 pm, Jarkko Oranen <chous...@gmail.com> wrote: > > On Aug 9, 7:54 pm, CuppoJava <patrickli_2...@hotmail.com> wrote: > > > > > Hello everyone, > > > Just for educational purposes, I'm writing a simple lisp compiler and > > > am stuck on a small problem. > > > > > I'm trying to write a function called (compile-function), which will > > > take a function as input and compile it. > > > > > If that function calls other functions, I would like (compile- > > > function) to automatically compile the called functions as well. > > > > > But I'm stuck on how to tell whether a function will be called or not. > > > Particularly when functions are passed around as objects. > > > > > So the question is this: Given a function f, how can I find all the > > > functions that f depends on? > > > > I don't think that's feasible, if it's even possible in the first > > place. > > > > Functions that the parent function calls directly you can of course > > try to compile whatever you encounter in a function call form; just > > check if the operator is a known global function, and compile it. > > However, if the operator is a local variable (ie. a function passed as > > a parameter) there's no reliable way to find out what function it is. > > It might even be a runtime-generated function (by eval) > > > > Since you can't know what functions will be called, the generated code > > must somehow verify that it's calling a function in the first place, > > perhaps invoke the compiler (if all functions must be compiled), and > > then execute it. > > > > -- > > Jarkko > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en