Huge Lookup Lists in SPIN
Rumple
Posts: 38
I'd like to implement a lookup list with an absurd number of expressions (2048, to be exact). I'm having trouble fitting the comma-delimited expression list (in hex) on one line in the editor...and it doesn't like it when I try to spread it over multiple lines.
I was wondering if anyone knew how to either spread the list over more than one line or how to define the list somewhere and "import" it into the LOOKUP command.
Should I use a huge CASE block instead? While playing with smaller lists, I've noted that LOOKUP generates much more compact code than CASE. I figured LOOKUP stands a chance of being faster, but I may be wrong.
Thanks.
I was wondering if anyone knew how to either spread the list over more than one line or how to define the list somewhere and "import" it into the LOOKUP command.
Should I use a huge CASE block instead? While playing with smaller lists, I've noted that LOOKUP generates much more compact code than CASE. I figured LOOKUP stands a chance of being faster, but I may be wrong.
Thanks.
Comments
Do you know whether or not that's the case with the CASE command too?
Can you give an example of what your expressions look like?
When storing the elements of a table it is not necessary to extend one line. The style shown below is easier, I believe, and helps one re-arrange small groups within the table (if they exist).
EDIT: Jon (AKA JonnyMac) posted the same idea of breaking up the list into multiple lines while I was composing my post.
The SPIN line that does the work looks like this:
outa[12..23]:=lookup(ina[0..11]:$1A1,$177,$A21,$A12,$B60,$717,$550,$02A,...on and on and on...)
So far. I haven't actually run any code yet, just seeing what compiles.
The project is still in the "playing with ideas" stage, so I'm certainly willing to listen to alternative methods if anyone would like to contribute one..
Thanks again.
You might try downloading a FREE text editor for generic computer work. I use Gedit and it is available both for Linux and Windows. I transfered the DATA from a spreadsheet to clean it up.
++++++++++++++++++++++++++++++
I did exactly what you desire to do in pfth Forth on the Propeller and the problem is hidden white space characters. Gedit will allow you to see and remove them with a FIND and REPLACE. Even an extra normal space may cause trouble in some instances.
2048 items is no problem at all. I just used CUT and PASTE and made sure that everything was using ASCII (not UTF-8 or UTF-16). Stay with LOOKUP for a position search as CASE is testing each character with a true or false.
With DATA, you can do other searches that are faster if you put all 2048 items in a simple ARRAY and if they are all numbers they can be represented as binary Longs, signed or unsigned.
++++++++++++++++++++++++++
Sorting adds a whole additional aspect to what you desire. What kind of sort are you considering?
I pre-sorted all my DATA in a spreadsheet and then just copied the list that was in the order I required. This makes using the data extremely fast.
EDIT: BTW, ina[0..11] is the bit-reversed form of ina[11..0]. Is that what you really want? Maybe you just need to use the non-bit-reversed form.
But...FWIW, I did manage to hunt down the answer to my original inquiry which was "how do you spread a command over multiple lines?".
Here's Phil Pilgrim in a 5-year-old thread:
"To continue a line, put a { at the end and a } at the beginning of the continuation line. This effectively comments out the terminating carriage return. (I can't take credit for this trick, but I also can't remember who first came up with it.)"
This method does indeed work with LOOKUP command. Cool.