Plans for Euphoria
- Posted by D. Newhall <derek_newhall at yahoo.com> Oct 18, 2006
- 479 views
It's only been a few hours and I already have a list of stuff I'm going to do with the code. Go figure. Anyways here's what I'm planning to add and would like feedback on whether it'd be a good or bad idea. perform ------- Syntax: <variable> = perform <code> end perform Description: Keyword to allow pseudo-anonymous functions. It is essentially a self-contained body of code that is run once and returns a value. Example: -- Read all the text from the config file constant CONFIG_FILE_CONTENTS = perform sequence result object line line = gets(config_fn) while sequence(line) do result = append(result, line) line = gets(config_fn) end while end perform foreach ------- Syntax: foreach <variable> in <sequence> do <code> end foreach Description: Same as: for i=1 to length(string) do char = str[i] if char ... end for Loops through each element of a sequence and allows you to use the variable to refer to that element. 95+% of all for loops in Euphoria do essentially this except with more typing. Element variable will most likely be read only to mirror the for loop variable. Example: -- Go through a list of people and make a list of the names of all adults sequence legal_adults foreach person in client_list do if person[AGE] >= 18 then legal_adults = append(legal_adults, person[NAME]) end if end foreach sequence of ----------- Syntax: sequence of <type> <variable> Description: Allows you to define a sequence where every element sequence must be of a specific type. Example: -- Get the name of a file and open it saving the file handle in a list sequence of integer file_handles integer fn file_handles = {} while length(file_handles) < 30 do -- Only 30 files can be opened fn = open(prompt_string("Name of next file:"), "r") if fn > -1 then file_handles &= fn end if end while Local Constants --------------- Syntax: [function|procedure] <name>(<arguments>) constant <name> = <value> <code> end [function|procedure] Description: I want to allow users to declare constants locally inside functions and procedures. This is something that I have constantly found limiting because I've wanted to declare sequence indeces as constants for use in one function but have to declare them for use in all following code. Plus, it's logical. Why can you declare local variables but not local constants since they are practically the same? Example: -- `distance` returns the distance between two points function distance(point a, point b) constant X = 1, Y = 2 return sqrt(power(b[X] - a[X], 2) + power(b[Y] - a[Y], 2)) end function -- distance Those are the only things I'm currently thinking about adding to the language. I've needed foreach so much that I wrote my own pre-parser to do it for me which has a big overhead. perform came to me during all those times I've defined a constant and needed to check every element of a sequence before setting it (if you can do it in Lisp why not Euphoria?). Besides trying to add stuff I'm going to port Euphoria to as many OSes as possible. My first platform is going to be the PowerMac so I can use it at work followed by hopefully either ZETA and/or the BSDs (ZETA would require more work but I don't have a OpenBSD or NetBSD computer right now). A Mac port is essentially guaranteed at this point because even if I don't have the time to do it I know other people that really want Euphoria on the Mac as well who would be quite happy to do it.