quick Forth question
Can anyone help me with a tiny Forth script? Can never quite get my head around the language. I'm trying to set up an if-else based on whether a mfg tag exists (or whether writing a mfg tag succeeded or not) I'm trying: add-tag ak 0 catch if 2drop . Laptop already activated cr then But, if ak already exists, it simply says: Tagname already exists ...rather than executing my conditional code. Also experimented with find-tag but couldn't figure it out. cheers, Daniel ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel
Re: quick Forth question
On Mon, Jan 25, 2010 at 10:59, Daniel Drake d...@laptop.org wrote: Can anyone help me with a tiny Forth script? Can never quite get my head around the language. I once wrote pen plotter programs in FORTH for fractals, to test the plotter mechanism. Hypnotic. I'm trying to set up an if-else based on whether a mfg tag exists (or whether writing a mfg tag succeeded or not) I'm trying: add-tag ak 0 catch if 2drop . Laptop already activated cr then But, if ak already exists, it simply says: Tagname already exists ...rather than executing my conditional code. That isn't very FORTHish, to have the argument to add-tag come after. Is that right? Your description is incomplete, and looks incorrect. My guess is that add-tag gives you the Tagname already exists message, and then FORTH continues, executing your conditional when it gets to it, and dropping two items from the stack. Please check. Here is what we need in order to comment usefully: Stack picture before starting. Expected result of add-tag, with stack picture. Expected result of ak, with stack picture. Is ak the address of a string? We're OK about putting 0 on the stack. Expected result of catch, with stack picture. Once you have all of that, you may not need our help. You can compare it with what actually happens by inserting stack display words. Also experimented with find-tag but couldn't figure it out. cheers, Daniel ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel -- Edward Mokurai (默雷/धर्ममेघशब्दगर्ज/دھرممیگھشبدگر ج) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://www.earthtreasury.org/ ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel
Re: quick Forth question
daniel wrote: Can anyone help me with a tiny Forth script? Can never quite get my head around the language. I'm trying to set up an if-else based on whether a mfg tag exists (or whether writing a mfg tag succeeded or not) I'm trying: add-tag ak 0 catch if 2drop . Laptop already activated cr then maybe something like: ak find-tag if 2drop . Laptop already activated cr then i'm pretty much a neophyte too, but i believe the commands that one types at the ok prompt that feel like command, with trailing args, should be avoided when scripting. i'm sure they can be used, but no doubt some special sauce is needed. paul But, if ak already exists, it simply says: Tagname already exists ...rather than executing my conditional code. Also experimented with find-tag but couldn't figure it out. cheers, Daniel ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel =- paul fox, p...@laptop.org ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel
Re: quick Forth question
On 01/25/2010 12:05 PM, Paul Fox wrote: maybe something like: ak find-tag if 2drop . Laptop already activated cr then i'm pretty much a neophyte too, but i believe the commands that one types at the ok prompt that feel like command, with trailing args, should be avoided when scripting. i'm sure they can be used, but no doubt some special sauce is needed. I worked it out. : check-ak add-tag ak 0 eval ; ok ' check-ak catch if . Laptop already activated cr then If you want to use it in a word then you need ['] rather than ' : do-me ['] check-ak catch if . Laptop already activated cr then ok do-me You can think of ' as the C operator. ' gets the reference to the word and that's what you have to give to catch so it can grab the exception. -- Richard A. Smith rich...@laptop.org One Laptop per Child ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel
Re: quick Forth question
2010/1/25 Richard A. Smith rich...@laptop.org: I worked it out. : check-ak add-tag ak 0 eval ; ok ' check-ak catch if . Laptop already activated cr then Thanks muchly! It works well. Daniel ___ Devel mailing list Devel@lists.laptop.org http://lists.laptop.org/listinfo/devel