lookup and lookdown
Dave Hein
Posts: 6,347
lookup and lookdown have the features described in the propeller manual, but they also have an undocumented·conditional-execution feature.· lookdown will evaluate each expression until it finds a matching value.· lookup will evaluate the first N expressions in the list, where N is the index value.· Here are a couple of examples:
x := 6
lookdown(5 : x--, x--, x--)
I believe this will return an index of 2, and x will have a final value of 4.· Only the first two "x--" expressions are executed, but not the third.· lookup seems to execute expression sequentially up to the selected item, just like lookdown.· Here is an example of lookup.
x := 6
lookup(3 : x++, x++, x++, x++, x++)
This should return a value of 8, and the value for x will be 9.· Does anybody use the conditional evaluation feature of lookup and lookdown?· Should it be documented in the propeller manual, or is it best not to depend on this feature in the future?· One use I can see is to emulate the C language conditional evaluation feature, such as in the following expression:
if (x > 5 || x-- >· 0)
which could be written in Spin as
if lookdown(true : x > 5, x-- > 0)
Dave
x := 6
lookdown(5 : x--, x--, x--)
I believe this will return an index of 2, and x will have a final value of 4.· Only the first two "x--" expressions are executed, but not the third.· lookup seems to execute expression sequentially up to the selected item, just like lookdown.· Here is an example of lookup.
x := 6
lookup(3 : x++, x++, x++, x++, x++)
This should return a value of 8, and the value for x will be 9.· Does anybody use the conditional evaluation feature of lookup and lookdown?· Should it be documented in the propeller manual, or is it best not to depend on this feature in the future?· One use I can see is to emulate the C language conditional evaluation feature, such as in the following expression:
if (x > 5 || x-- >· 0)
which could be written in Spin as
if lookdown(true : x > 5, x-- > 0)
Dave
Comments
lookdown is a little more interesting, and it could be implemented with the case statement as well.· Does anybody use lookdown, or do you prefer to use case to perform that function?
Dave
The potential for bugs there is rather large...
Thanks for the info there however. I did not know about this.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
I just used lookup for my virtual keyboard to translate x tile location into a keycode...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Though it is an interesting feature, it does seem like there would be better, more readable/understandable ways to do it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
Fast Inter-Propeller Comm - Fast communication between two propellers (1.37MB/s @100MHz)!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
DAT
· header byte "!EFX"
...
· repeat
··· c := com1.rxcheck·········································· ' check serial input
··· if (c => 0)···················································· ·' if char available
····· if (ucase(c) <> byte[noparse][[/noparse]header][noparse][[/noparse]cmdstate++])······· ' validate header
······· cmdstate := 0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
I looked at the Spin interpreter code, and it uses the same section of code to implement lookup, lookdown and the case statement.· That's why lookup evaluates the first N expressions.
Dave