Jump to content
IGNORED

EACH command in TI LOGO II


Recommended Posts

After a nearly 40 year break I am again active in the TI99 World. I am well versed in Extended Basic, but LOGO II was new to me until a few weeks ago. One command, that is potentially very useful, is the EACH command in combination with TELL and YOURNUMBER. It is only mentioned in the manual as a means of addressing multiple sprites with one list of commands, which implies that it is limited to using values between 0-31. But is this really so?

I made an ADDLIST procedure like this:

TO ADDLIST :MYLIST

MAKE "ANSW 0

TELL :MYLIST

EACH [MAKE "ANSW :ANSW+YOURNUMBER]

OUTPUT :ANSW

END

This adds all entries in the list and returns the total like this example:

PRINT ADDLIST [200 202 204 1000]

which returns 1606 as it should.

This looks like an efficient method compared to traversing a list with FIRST, BUTFIRST and all that recursion stuff. I can think of other scenarios, where this might be useful. A CASE like test construction is one. Another controls the order of execution of some procedures depending on the order of the numbers in a list, which can easily be changed. Lots of possibilities...

But all is not well. In another test I wrote the combination TELL 34 HOME, which to my surprise caused two character sets to change color to light red and red, and after using a list with numbers [100 ... 109] and later displaying the :BALL sprite, it was partially messed up. These problems could be replicated. So they are real. Apparently, having numbers beyond 31 in the list used with EACH writes interesting things to interesting addresses in memory. Some of which have a visible effect.

The question is... Was the TELL/EACH command combination only ever intended to be used with values 0-31 for sprite addressing, or can it be used with any integer value up to the signed 16 bit limit?

I have ordered a LOGO II package and is expecting it in a week or two, to allow me to work on real iron, but currently I only program LOGO II using the Classic99 emulator. So there is a chance this is an emulator issue.

Opinions and advice is most welcome, Thanks.

regards

Jesper

  • Like 1
Link to comment
Share on other sites

Nobody has commented so here is my very un-informed view.

(I have never used LOGO)

 

With the line 

TELL 34 HOME

I think the program did what you asked in that it assigned  HOME to 34. :) 

 

What that actually means I have no idea but it seems to affect the color table.  What is 34 in LOGO's view? 

We would need to do some serious study of the internals I think. 

You may have un-covered that TELL does not check its arguments for validity very aggressively.

Maybe you meant to type

TELL HOME 34 

to assign the value 34 to HOME?

 

"The question is... Was the TELL/EACH command combination only ever intended to be used with values 0-31 for sprite addressing, or can it be used with any integer value up to the signed 16 bit limit?"

 

It would have been very short-sighted to restrict EACH for use with sprites only.

In other languages EACH or FOREACH is a higher-order-function (HOF) that lets you iterate over the items in a list with some other function.

If this is true you should be able to iterate on any list and EACH will perform some code on each item in the list.

I will leave it to you to test my hypothesis.

I have been wrong before. (Just ask my wife)

 

 

  • Haha 3
Link to comment
Share on other sites

Hi

 

Thanks for your reply.

 

If I am to believe the manual, the TELL command is used to direct subsequent graphics commands to an object, which becomes the "active object". If used with a list of numbers, commands are directed to all sprites in the list. TELL used with a number (as in my example) designates a sprite. Examples in the manual only mentions its use in connection with sprites. The manuals also states, that EACH takes a list of commands as inputs and runs the list for each active sprite. The second description made me think, that while it is intended for handling of sprites, it works with any command, and it can therefore be used as a kind of FOR-NEXT loop with the unique capability, that you control which values are used in the loop. As it traverses the list each value is extracted with the YOURNUMBER directive. And as my example shows, this works. But it seems there are side effects for some values beyond the sprite range.

 

HOME is used to move the turtle to the centre of the screen and orient it upwards, if it is active. As a protected command word it can not be reassigned to become a variable. (The system ignores any attempt) My example 'TELL 34 HOME' was perhaps not the best, because TELL only expects one argument (a list), and HOME is in effect a separate command. The tricky thing about LOGO II is, that it uses spaces as separators between commands as well as arguments to procedures, and it keeps its own tabs on whether it deals with one or the other. So you can make strange looking code like this, which will print a menu of strings held in a list (txt) and starts printing at x,y. It could have been a one-liner, but I try to have at least some formatting in my code (-:

 

TO MYMENU :X :Y :TXT          

 CS                            

 REPEAT :Y [PRINTCHAR 13 ]     

 REPEAT LENGTH :TXT [REPEAT :X [PRINTCHAR 32 ] TYPE FIRST :TXT MAKE "TXT BUTFIRST :TXT PRINTCHAR 13 ]                    

 END                           

 

TELL can not be used to assign values to variables n LOGO II. For this purpose you have MAKE "A 34 (Set the variable A to numeric 34) or the similar CALL 34 "A, which just has the arguments in reversed order.

 

My guess is, that TELL explicitly sets up a list of numbers in memory, that can be used together with EACH and YOURNUMBER, and as you say, LOGO just does not check the values. In any case I think I can use values between 0-31 with impunity, because the commands handled by EACH can be any command - not just commands related to sprites. Of course this may conflict with any active sprites, whose numbers match the numbers in my list. But assuming you do not use sprites or do not use sprite related commands with EACH, all is well, I think. And TELL - EACH - YOURNUMBER it is a very convenient command combination.

 

regards

Jesper

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...