Re: Plans for Euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message

D. Newhall wrote:

> 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.

OK, I'll give my personal opinions regarding the items on your list.


> 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

Sorry, I can't see what we'd gain by this new keyword.
We can now do the same as in your example by using a normal function:

function read_config()
    -- Read all the text from the config file
    sequence result
    object line
    line = gets(config_fn)
    while sequence(line) do
        result = append(result, line)
        line = gets(config_fn)
    end while
end function
constant CONFIG_FILE_CONTENTS = read_config()



> 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

This is nice "syntactic sugar" IMHO, which can _increase readability_ of the
code. (It's almost impossible to overestimate the importance of readability.)


> sequence of
> -----------
> 
> Syntax:
> 
> sequence of <type> <variable>

Just a short note:
I'm pretty sure you mean

sequence of <type> <variable> [, <variable>, ...]

so that it'd be possible to declare more than one variable after
'sequence of <type>', no?

> 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

I would appreciate this.
Currently, I do something similar by using user-defined types, e.g.
   sequence_of_integer x, y, z

This works fine, but the problem is that this way type-checking sometimes
can take a long time! Your suggested method should work considerably faster,
otherwise I can't see an advantage.


> 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

I agree that this would be a useful and logical enhancement.

<snip>

Regards,
   Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu