Page 1 of 2

Euphoria Sequence

Posted: Mon Jun 24, 2013 6:48 pm
by ken_anthony
I'm scavenging some routines from a program I wrote years ago in the Euphoria language.

Euphoria is not the language for writing professional applications but it really is the best for developing algorithms. Sequences are the reason. Sequences are THE data structure for the humble programmer.

My hope is limited, but a sequence data type would be jaw dropping.

Re: Euphoria Sequence

Posted: Mon Jun 24, 2013 7:02 pm
by Zach
I looked at some quick examples in google.

This looks like a List ??

We can also have Structured Lists, Arrays, Maps and such.

Maybe its more complicated than that, but it looks like you could get the functionality you are looking for by using one of the mentioned things above.

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 12:06 am
by ken_anthony
No, it's not a list or a map. You might call it a ragged array. It is a very subtle, elegant data structure.

Any programmer that uses a sequence will fall in love and have their heart broken when they can't use them anymore... seriously.

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 6:46 am
by Zach
Well you certainly have me curious... what is a "ragged" Array ?

For all intents, the stuff I looked at seemed like the special part was some of the stuff you could do to the data type, as opposed to the data type itself ? (run this algorithm against it, run that, etc)
Where has my understanding gone wrong?

It certainly seems that with a little finaggling, you could probably emulate a Sequence in PureBasic. Although if you need to resize an array you lose the ability to use multiple dimensions.

Using a Dynamic Linked List seems like a more probable solution. Since they can have any number of elements and can also use User Defined Types.

So in a round-about way, you could define your Sequence as a User Defined Type. Then possibly write some helper procedures to manipulate data based on that format ?

Of course I could be very wrong. In which case I will crawl back under my rock :oops:

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 7:33 am
by ken_anthony
what is a "ragged" Array ?
An array is regular: square, cubed, etc. A ragged array is not.
you could probably emulate a Sequence in PureBasic
You might think so, meaning you need to understand Euphoria sequences better. It's a combination of things.

Zach, you are too valuable to be crawling under rocks. Instead, get a copy of Euphoria and look at some of the examples (every examples uses sequences it only has two data types and the other is simply a single number, the atom.)

Version 3 was written by the original author. Version 4 is written by a team.

I was originally going to write my project in Euphoria but the GTK library had a callback problem that didn't allow it to compile (and using an interpreter is not my idea of a professional product for distribution.)

A sequence has no dimensions. It has a length and each item is indexed. Each item can be another sequence of any length. That in turn can contains sequences of any length.

Here's an example of code (not entirely original to me) I'm going to borrow from an old Euphoria project I wrote (my first) and translate into PureBasic...

Code: Select all

temp = {{},{}}
for Index = 1 to 360 do
    temp[1] = append(temp[1], sin(Index*PI/180))
    temp[2] = append(temp[2], cos(Index*PI/180))
end for
constant sin_lookup = temp[1], cos_lookup = temp[2]

function Rotate(sequence shape, atom facing)
	for ndex = 1 to length(shape) do
      	shape[ndex] = {
			(shape[ndex][Xord] * cos_lookup[facing])-(shape[ndex][Yord] * sin_lookup[facing]),
			(shape[ndex][Yord] * cos_lookup[facing])+(shape[ndex][Xord] * sin_lookup[facing])}
	end for
	return shape
end function
A sequence can act as a vector. You can perform math on the entire sequence without having to spin through the elements. Which means I could have probably written this snippet better.

shape in this case is just a polygon, but shape could also be a collection of polygons. rotate takes a shape and makes it a new shape point in any of 360 facings.

The thing about a sequence is it can be anything. It's a universal type with no requirement for the programmer to do memory allocation or deallocation. In Euphoria the concept of TYPE is any function you want to validate a sequence.

It's more addicting than crack or sex.

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 7:45 am
by ken_anthony
This is really the key line...

Code: Select all

constant sin_lookup = temp[1], cos_lookup = temp[2]
Note that I took parts of a mutable sequence and assigned it to two immutable sequences without having to specify the dimensions of the two constant sequences.

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 8:00 am
by ken_anthony
Although if you need to resize an array you lose the ability to use multiple dimensions.
Not an issue for a Euphoria sequence.

Euphoria actually has some of the same issues as PureBasic in that all programs may have multiple physical files but logically it's just one big file and order matters in both.

I'll just have to keep using PureBasic 'til my ideal language comes along (after I'm six feet under, if even then.)

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 12:08 pm
by Zach
Hmm well. Yes, it is definitely beyond my current level of understanding :idea:

We're in the same boat. I guess. My ideal language is probably different from yours, but it consists of one simple concept.
I tell the program to do something in plain English... It does it!

haha :mrgreen:

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 3:08 pm
by ken_anthony
Plain English is a nasty Trap. That's how Data got in trouble with the Enterprise holodeck creating the Moriarty character that could beat him!!! You do know that everything you need to know in life was once a Star Trek plot, right?

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 6:06 pm
by Zebuddi123
@ken_anthony does that mean Desi Arnaz and Lucille Ball were aliens ? lol

Zebuddi. :D

Re: Euphoria Sequence

Posted: Tue Jun 25, 2013 11:19 pm
by ken_anthony
Not Sure. But I do know Desi was the funny one.

Re: Euphoria Sequence

Posted: Wed Jun 26, 2013 10:04 pm
by langinagel
Howdy,

besides the Startrek stories, I do not get the grasp for the sequences.

It reminds me on old time MATLAB programming, juggling with vectors. Trying to change a single value in a vector or a field was a then (now hopefully easier) a real pain, that let me get thoughts on working with FORTRAN.

Now the same way: easy way to describe an array...but if you like to change specific values then you might face higher efforts.
In Purebasic now:
array(x,y,z) = whatever.w
or working with element-commands
or for those who like it, juggling with pointers on arrays or lists
From my perspective: the old fashioned way is more deterministic, better understandable.

And: sequences would be far away from the BASIC ANSI/ISO/IEC norm.

a "No, thanks" from my side.

LN

Re: Euphoria Sequence

Posted: Wed Jun 26, 2013 10:49 pm
by ken_anthony
If you like arrays, you should love sequences. They can do anything an array can and more.

Code: Select all

array(x,y,z) = whatever.w
becomes

Code: Select all

array[x][y][z] = whatever
Which may look a bit funny if your used to commas, but the power you get in exchange is more than worth training your habit to see it the new way.

For example, what if you just need two of three dimensions? With the array, you always have to deal with Z. With sequences it's just

Code: Select all

array[x][y]
Using the exact same sequence as above. Which means you could pass the same sequence to a 2D function or a 3D function. You can't do that with an array.

The beauty of a sequence is that is makes algorithms much more elegant. Beauty and elegance are qualities that all good code should have. A lot of programmers will have no idea what I mean by that last sentence. Those that do should be listened to.

Re: Euphoria Sequence

Posted: Wed Jun 26, 2013 10:56 pm
by ken_anthony
BTW, I caught <a href="http://www.cs.utexas.edu/users/EWD/tran ... .html">the irony of your tagline</a>.

Re: Euphoria Sequence

Posted: Wed Jun 26, 2013 10:57 pm
by ken_anthony
Well that didn't work. Let me try this: http://www.cs.utexas.edu/users/EWD/tran ... WD340.html