From: Enoch <ix...@ho...> - 2013-03-20 22:30:06
|
Hello AmForth-ers: Did any of you put "wordlists" into a good use? I suspect the answer is no for a simple reason. To use it, say, to create a private "scope" ("namespace") of words / variables / constants one needs to wrap each dictionary entry with calls to get-current, get-order, set-current, set-order, ... too much trouble. What if we decide that all names that begin with a tilde (~) should *automatically* be created into a specific private wordlist. How can we accomplish that? Here's my suggestion for your review: If I am correct the kernel word "header ( addr len wid -- voc-link )" is responsible for creating dictionary entries of all kinds. What if this "header" would begin with a call to a (e)deferred word, say, "autoscope" that would examine the new entry name (via "addr len") and would set the "wid" etc. as needed. In the best Forth tradition let this "autoscope" be initially a NOP and allow the programmer to introduce whatever naming scheme he/she desires via a subsequent IS. Am I missing something? Did I reinvent the wheel? :-) Thanks, Enoch. |
From: Matthias T. <mt...@we...> - 2013-03-21 18:41:53
|
Hi Enoch, > In the best Forth tradition let this "autoscope" be initially a NOP and > allow the programmer to introduce whatever naming scheme he/she desires > via a subsequent IS. A better place for such a hook would be (CREATE) (same asm file). And the default should be the standard behaviour (get-current). > Am I missing something? Did I reinvent the wheel? :-) I think you solve a problem, nobody else has ;) We'll see how much response you'll get.. Matthias |
From: Enoch <ix...@ho...> - 2013-03-22 17:53:33
|
Hello Matthias & All: Matthias Trute <mt...@we...> writes: > Hi Enoch, > > >> In the best Forth tradition let this "autoscope" be initially a NOP and >> allow the programmer to introduce whatever naming scheme he/she desires >> via a subsequent IS. > > A better place for such a hook would be (CREATE) (same asm file). And > the default should be the standard behaviour (get-current). > >> Am I missing something? Did I reinvent the wheel? :-) > > I think you solve a problem, nobody else has ;) We'll see how > much response you'll get.. *Thanks for the encouragement* I prepared a kernel patch, it's very simple, but ain't working, for some stupid reason, I guess :) The kernel patch is here: http://pastebin.com/8MShMtn4 (Sorry Erich, there's no other way with patches, unless you allow me to insert uuencoded text here). Here's a simple test case. ---------------------------------------------------------------------- wordlist constant private : scope ( c-addr u -- c-addr u wid ) over c@ [char] ~ = if private else get-current then ; ' scope is wlscope Trying to create anything "private" (e.g., 100 constant ~test) renders the dictionary inaccssible. Otherwise it functions as usual. ---------------------------------------------------------------------- I guess that without the Studio (i.e., going to the dark Windows side) I won't be able to figure this out, so please help. Thanks, Enoch. |
From: Enoch <ix...@ho...> - 2013-03-24 04:28:11
|
Hello Matthias & All, Just in case someone is interested in my kernel patching exercise for automatic wordlist selection :-) > I prepared a kernel patch, it's very simple, but ain't working, for some > stupid reason, I guess :) > The kernel patch is here: http://pastebin.com/8MShMtn4 Delving into the asm code I see that my current docreate.asm patch is insufficient since the created word is actually linked to the selected wordlist outside XT_DOCREATE. It would save some code and would be cleaner programming to put the equivalent to [.dw XT_GET_CURRENT, .dw XT_STOREE] inside XT_HERE except for the XT_COLON / XT_SEMICOLON "smudge" issue. Will have it done tomorrow. > Here's a simple test case. > > ---------------------------------------------------------------------- > > wordlist constant private > > : scope ( c-addr u -- c-addr u wid ) > over c@ [char] ~ = if > private > else > get-current > then > ; > > ' scope is wlscope I hope that I managed to persuade some of you that auto wordlist selection is a good thing ;-) Regards, Enoch. |
From: Erich W. <ew....@na...> - 2013-03-21 19:10:14
|
Hi, On 03/20/2013 11:29 PM, Enoch wrote: > Hello AmForth-ers: > > Did any of you put "wordlists" into a good use? yes. I use this to create a separate wordlist, which is used to parse a special source code structure. I need a special wordlist, because I need to *temporarily* "overload" the meaning of some important words. I have also used this to reduce the available wordlist on the serial interface after startup. Also, Lubos Pekny (forth.cz) uses wordlists to separate things. > I suspect the answer is no for a simple reason. To use it, say, to > create a private "scope" ("namespace") of words / variables / constants > one needs to wrap each dictionary entry with calls to get-current, > get-order, set-current, set-order, ... too much trouble. > > What if we decide that all names that begin with a tilde (~) should > *automatically* be created into a specific private wordlist. How can we > accomplish that? Well. I do use a number of words myself starting with ~ (tilde). And I do not agree at all, that creating special prefixes *for everyone* and do something entirely different with those words, is the way to go. Even if I need to explicitly enable the feature, I do not want to have the freedom of choosing token names stumpled upon. Remember the FORTRAN rule of "undeclared variables starting with [I-N] are assumed integer"? How awkward. Can I at least choose the prefix freely? Can it be more than one character? Recognizers would be the way to go, I think. Who stops you from implementing this for your use and put the resulting code into a message on the list ? (reminder: I will not look at code elsewhere) And why do you want your solution to be included into the amforth distribution and *enabled by default*? What use cases for the suggested feature are you currently looking at? Are there other ways to accomplish your goal? Why is this way the ultimate thing to do? Imho Forth is about simplicity. You suggest to add a bit of complexity (automagic different behaviour). > > Here's my suggestion for your review: > > If I am correct the kernel word "header ( addr len wid -- voc-link )" is > responsible for creating dictionary entries of all kinds. What if this > "header" would begin with a call to a (e)deferred word, say, "autoscope" > that would examine the new entry name (via "addr len") and would set the > "wid" etc. as needed. > > In the best Forth tradition let this "autoscope" be initially a NOP and > allow the programmer to introduce whatever naming scheme he/she desires > via a subsequent IS. But that is a penalty of 1 call to noop for every call of header, and for everyone. |
From: Matthias T. <mt...@we...> - 2013-03-21 19:44:04
|
Hi, > Recognizers would be the way to go, I think. Thats an interesting point. Until now, recognizers are not considered part of the *compiler*, but part of the (outer) *interpreter*. That means, they are used to find the proper meaning of an *already defined* word, but they are not active *during the definition* of a word. Fascinating idea, indeed. Matthias |
From: Enoch <ix...@ho...> - 2013-03-21 22:00:48
|
Erich Waelde <ew....@na...> writes: > Hi, > > On 03/20/2013 11:29 PM, Enoch wrote: >> Hello AmForth-ers: >> >> Did any of you put "wordlists" into a good use? > > yes. I use this to create a separate wordlist, which > is used to parse a special source code structure. I need > a special wordlist, because I need to *temporarily* "overload" > the meaning of some important words. > > I have also used this to reduce the available wordlist on > the serial interface after startup. > > Also, Lubos Pekny (forth.cz) uses wordlists to separate > things. So we all agree that wordlists are important. What I asked myself was how to make them easier to use. >> I suspect the answer is no for a simple reason. To use it, say, to >> create a private "scope" ("namespace") of words / variables / constants >> one needs to wrap each dictionary entry with calls to get-current, >> get-order, set-current, set-order, ... too much trouble. >> >> What if we decide that all names that begin with a tilde (~) should >> *automatically* be created into a specific private wordlist. How can we >> accomplish that? > > Well. I do use a number of words myself starting with ~ (tilde). And > I do not agree at all, that creating special prefixes *for everyone* > and do something entirely different with those words, > is the way to go. Even if I need to explicitly enable the feature, > I do not want to have the freedom of choosing token names stumpled upon. > Remember the FORTRAN rule of "undeclared variables starting with [I-N] > are assumed integer"? How awkward. Can I at least choose the prefix > freely? Can it be more than one character? Recognizers would be the > way to go, I think. The thought of imposing naming conventions on other programmers did not even cross my mind :-) > Who stops you from implementing this for your use and put the > resulting code into a message on the list ? (reminder: I will not > look at code elsewhere) And why do you want your solution to be > included into the amforth distribution and *enabled by default*? I will contribute my code and will let Matthias decide on its worthiness and yes, I can live with a rejection :-) Why do I want to have "my" solutions included into the AmForth distribution... I am puzzled by this question -- isn't it the very nature of OSS development, free competition of ideas. By the way, having a "benevolent dictator" who decides about the worthiness of ideas / implementations is well rooted into the OSS culture too. If code is short it will go to the mailing list. If it is long, I disagree, its place is a seperate "pastebin". > What use cases for the suggested feature are you currently looking at? 1. Keeping certain words/variable/constants private, i.e., unknown outside a certain source file. 2. In a large library, say, graphic library, put all public words/... on a seperate wordlist. > Are there other ways to accomplish your goal? Why is this way the > ultimate thing to do? I suggested a kernel hack but I can see high level help in handling wordlists too. How do you utilitize wordlists, using raw get-current, set-current, etc. calls? > Imho Forth is about simplicity. You suggest to add a bit of complexity > (automagic different behaviour). Default behavior would be set-current (of-course). >> Here's my suggestion for your review: >> >> If I am correct the kernel word "header ( addr len wid -- voc-link )" is >> responsible for creating dictionary entries of all kinds. What if this >> "header" would begin with a call to a (e)deferred word, say, "autoscope" >> that would examine the new entry name (via "addr len") and would set the >> "wid" etc. as needed. >> >> In the best Forth tradition let this "autoscope" be initially a NOP and >> allow the programmer to introduce whatever naming scheme he/she desires >> via a subsequent IS. > > But that is a penalty of 1 call to noop for every call of header, and for > everyone. Get serious Erich, that's a one-time compile-time penalty :-) 10000 dictionary-entries × 10µS penalty = 0.1s Regards, Enoch. |