Re: Questions about anonymous functions and classes/functions declarations

Derk Gwen <derkgwen@HotPOP.com>
6 Oct 2003 21:24:40 -0400

          From comp.compilers

Related articles
Questions about anonymous functions and classes/functions declarations mrfaro@libero.it (Gabriele Farina) (2003-10-04)
Re: Questions about anonymous functions and classes/functions declarat derkgwen@HotPOP.com (Derk Gwen) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat lsantil@calstatela.edu (Louis Paul Santillan) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat haberg@matematik.su.se (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat joachim.durchholz@web.de (Joachim Durchholz) (2003-10-06)
Re: Questions about anonymous functions and classes/functions declarat geoff@wozniak.ca (Geoff Wozniak) (2003-10-08)
Re: Questions about anonymous functions and classes/functions declarat joachim.durchholz@web.de (Joachim Durchholz) (2003-10-08)
Re: Questions about anonymous functions and classes/functions declarat witness@t-online.de (Uli Kusterer) (2003-10-13)
[1 later articles]
| List of all articles for this month |
From: Derk Gwen <derkgwen@HotPOP.com>
Newsgroups: comp.compilers
Date: 6 Oct 2003 21:24:40 -0400
Organization: Quick STOP Groceries
References: 03-10-004
Keywords: code, design
Posted-Date: 06 Oct 2003 21:24:40 EDT

# I'm planning to try to implemente a programming language. I got a lot
# of ideas, and I know how to implements them except for anonymous
# functions. Where I have to store them?? I have to have a table only
# for anonymous functions?? Someone asks to me to treat them as
# constants, but I can't understanda how to develop it.


(An important gotcha is do you permit nonlocal stack variables to be
referenced within the function? If so, you'll need some way to
reconstruct the environment when called; if the function value cannot
be exported outside the original scope, you can use displays or stack
links that were developed for Algol 60 and Pascal. If the function
can be exported outside the original scope, you'll need some form of
continuations.)


Function bodies are byte vectors, and not that different that normal
character strings (or in some languages they are normal character
strings) in allocation and moving, especially if they are relocation
free. For the function, you'll need the body and possible context
information, which can be regarded as a structure associated with byte
vector. Any techniques you would normally use for character strings
and structures should apply to the functions.


In a compiled languages, the function body is going to be known at
compile time and in modern languages, immutable. So like a string
constant stored once in a read only text page and then a pointer to
the string passed around, you can store the function body once in a
read/executable page and pass around a pointer. If you needed
additional context information, like a link segment address or stack
link or a continuation pointer, the compiled function can be code to
create a structure value from a pointer to the function body and the
other linkage information.


# Do you think this can be useful and can be implemented?? There could be any
# problems??


Algol 68 has anonymous functions but they cannot be exported out of
scope. Pure Lisp has anonymous functions allocated on the heap and
without nonlocal stack variables. Successors to Lisp have anonymous
functions with continuations. Postscript functions are anonymous byte
vectors.


--
Derk Gwen http://derkgwen.250free.com/html/index.html


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.