From: Enoch <ix...@ho...> - 2013-03-24 09:03:15
|
Hello Matthias & All: wlscope, "wordlist scope", is a deferred word which enables AmForth appl to choose the wordlist for a new voc entry based on its name. For example, put all created words whose name begins with a tilde (~) on a private wordlist. The default action is get-current. Please find in <http://pastebin.com/KEWfnWNz> a tested new patch for your review against AmForth r1400. This patch enables do the following: ====================================================================== wordlist constant private : scope ( c-addr u -- c-addr u wid ) over c@ [char] ~ = if private else get-current then ; ' scope is wlscope ---------------------------------------------------------------------- > private show-wordlist ok > 911 value ~sos ok > private show-wordlist ~sos ok ====================================================================== I agree, the above is just "semantical sugaring" to the normal use of wrappers: get-current private set-current 911 value ~sos set-current Don't know about you guys, I prefer sweetening my AmForth coffee :-) Regards, Enoch. |
From: Matthias T. <mt...@we...> - 2013-03-25 19:21:39
|
Hi Enoch, looks fine GIve me some more days to think about it (Im currently busy with other things) I find the sequence "(create) !e" sligthly strange. Your smudge change from an simple XT to WID-XT makes sense. Matthias > Hello Matthias & All: > > wlscope, "wordlist scope", is a deferred word which enables AmForth appl > to choose the wordlist for a new voc entry based on its name. For > example, put all created words whose name begins with a tilde (~) on a > private wordlist. The default action is get-current. > > Please find in <http://pastebin.com/KEWfnWNz> a tested new patch for > your review against AmForth r1400. This patch enables do the following: > > ====================================================================== > > wordlist constant private > > : scope ( c-addr u -- c-addr u wid ) > > over c@ [char] ~ = if > private > else > get-current > then > ; > > ' scope is wlscope > |
From: Enoch <ix...@ho...> - 2013-03-27 13:02:09
|
Matthias Trute <mt...@we...> writes: > Hi Enoch, > > looks fine > > GIve me some more days to think about it (Im currently > busy with other things) I find the sequence "(create) !e" > sligthly strange. Your smudge change from an simple > XT to WID-XT makes sense. > > Matthias Hello Matthias, I look forward to your critical reading of the patch. Currently I'm using the mechanism to emulate Python private names convention (*) but this scope word is bound to evolve. Regards, Enoch. (*) In Python names in a "module" which begin with underscore cannot be imported to another via "from module import *". P/S If you approve of this patch I suggest submission of an RfD to forth200x.org. ---------------------------------------------------------------------- wordlist constant _private get-order _private rot rot 1+ set-order : scope ( c-addr len -- c-addr len wid ) over c@ [char] _ = if _private else get-current then ; ' scope is wlscope |
From: Matthias T. <mt...@we...> - 2013-03-27 18:16:21
|
Hi Enoch, Only one remark so far. You defined the scope stack effect as ( addr len -- addr len wid ) Usually forth follows the conecpt, that a word consumes its parameters to generate the new data. I'd prefer to keep this idea as the general design pattern. That changes scope to the stack effect (addr len -- wid ) That requires a few more instructions (a 2DUP in (CREATE) and the get-current needs some glue code to be usable as a scope provider. Nothing really big, I think. Your scope example turns to something like : scope ( addr len -- wid) drop c@ [char] _ = if _private else get-current then ; (not tested) The standard scope provider that uses GET-CURRENT will be : current-scope drop drop get-current ; > P/S If you approve of this patch I suggest submission of an RfD to > forth200x.org. You're a brave man ;) Matthias |
From: Enoch <ix...@ho...> - 2013-03-27 20:59:28
|
Matthias Trute <mt...@we...> writes: > Hi Enoch, > > Only one remark so far. > > You defined the scope stack effect as ( addr len -- addr len wid ) > Usually forth follows the conecpt, that a word consumes its parameters > to generate the new data. I'd prefer to keep this idea as the general > design pattern. That changes scope to the stack effect (addr len -- wid ) > That requires a few more instructions (a 2DUP in (CREATE) and the get-current > needs some glue code to be usable as a scope provider. Nothing really big, I > think. Hello Matthias, You are absolutely correct, Leo Brodie writes in 4.16 "Tip: Let definitions consume their arguments", but I have the feeling that he would have said (*) but you can igone this advice if it adds uncessary cruft to your code :-) (*) Since I don't believe that he would advocate against the KISS principle. > Your scope example turns to something like > > : scope ( addr len -- wid) > drop c@ [char] _ = if > _private > else > get-current > then ; > > (not tested) > > The standard scope provider that uses GET-CURRENT will be > > : current-scope drop drop get-current ; > >> P/S If you approve of this patch I suggest submission of an RfD to >> forth200x.org. > > You're a brave man ;) I think that their standards committee gives too much voice to guys from the PC era while Forth "is born" for the small µC in mind. Regards, Enoch. |
From: Matthias T. <mt...@we...> - 2013-03-28 19:09:03
|
Hi Enoch, > > Only one remark so far. And now my second one. Its more a vague idea, not a streamlined chain of reason including a smart solution. Sorry. It is related to the way, the newly created word list entry is linked into it. HEADER gets the WID for which the new word is created. The same WID is used later on to be stored into the same wordlist: The surprising and "unmotivated" XT_STOREE in words that call (CREATE) like VARIABLE etc. Withing these words there is nothing that could explain it. IMHO. At the first glance there is no reason to duplicate and decentralize the STOREE, but there is one, rather far away: Colon word definitions are hidden until the semicolon is executed. And the way, the search wordlist (get-order) is handled if the compile-to wordlist (Current) contains one of the get-order's entries. What I would like to have is a single place where the new word is defined and linked into the right wordlist. Its probably simple, but far from trivial. I'll think about it. Its a fascinating change. Much more demanding than I thought initially... Matthias PS: simply said: just change the stack effect of HEADER from (addr len wid -- wid) to something better ;) |
From: Enoch <ix...@ho...> - 2013-03-29 15:01:39
|
Hello Matthias, Matthias Trute <mt...@we...> writes: > Hi Enoch, > >> > Only one remark so far. > > And now my second one. Its more a vague > idea, not a streamlined chain of reason including > a smart solution. Sorry. > > It is related to the way, the > newly created word list entry is linked into it. > HEADER gets the WID for which the new word > is created. The same WID is used later on to be > stored into the same wordlist: The surprising and > "unmotivated" XT_STOREE in words that call > (CREATE) like VARIABLE etc. Withing these words > there is nothing that could explain it. IMHO. > > At the first glance there is no reason to duplicate and > decentralize the STOREE, but there is one, rather far away: > Colon word definitions are hidden until the semicolon is > executed. And the way, the search wordlist (get-order) > is handled if the compile-to wordlist (Current) contains one > of the get-order's entries. > > What I would like to have is a single place where the new word > is defined and linked into the right wordlist. Its probably simple, > but far from trivial. I'll think about it. > > Its a fascinating change. Much more demanding than I thought > initially... > > Matthias > > PS: simply said: just change the stack effect of HEADER from > (addr len wid -- wid) to something better ;) #1 There is a strong argument to merge XT_HEADER with XT_DOCREATE as XT_HEADER is called only by XT_DOCREATE. That's what Mr. KISS always says :-) #2 As for "wlscope" stack effect, if the price for our AmForth idea to be admitted to the Forth community "hall of fame" (forth200x.org, that is) would be for wlscope to consume its arguments, so be it: We can do it neatly (i.e., without irritating ol' Mr. KISS) by rearranging the order of activities in XT_HEADER and call XT_WLSCOPE after the name-string validity check (non-empty) and after creating the dictionary header in Flash (i.e., just before linking). #3 Based on your response to #1 I can submit a patch, if you like. Your code is, as you say, indeed dark (not enough comment lampposts) but is quite easy to read! Regards, Enoch. |
From: Enoch <ix...@ho...> - 2013-03-30 07:57:10
|
Enoch <ix...@ho...> writes: > Matthias Trute <mt...@we...> writes: >> I just applied your patch with my modification for the >> the stack effect of the scope word. My second remark >> would not change that (user visible) interface so I think >> we can now play with the idea and can clean up the >> code behind the scenes with less pressure ;) > > Hello Matthias, > > Good, did svn update deciding conflicts in your favor :-) > > Regarding the behind the scenes cleanup, do you allow merging of > XT_HEADER into XT_DOCREATE ? > > Regards, Enoch. Hello again, Below is an advanced example for (the revised) "wlscope" use. It shows how to encapsulate a large library of words. Note that since the following code allows multiple scope installs we can and perhaps should make "current-scope" invisible. Any comments? Regards, Enoch. ---------------------------------------------------------------------- wordlist constant can_list get-order can_list rot rot 1+ set-order : scope ( c-addr len -- wid ) 2dup 4 > if \ name length check s" can_" tuck icompare if \ name prefix check 2drop can_list exit then else drop then [ ' wlscope defer@ ] literal execute \ scope nesting safe ; ' scope is wlscope |
From: Matthias T. <mt...@we...> - 2013-03-29 15:37:54
|
Hi Enoch, I just applied your patch with my modification for the the stack effect of the scope word. My second remark would not change that (user visible) interface so I think we can now play with the idea and can clean up the code behind the scenes with less pressure ;) Matthias |
From: Enoch <ix...@ho...> - 2013-03-30 03:42:40
|
Matthias Trute <mt...@we...> writes: > I just applied your patch with my modification for the > the stack effect of the scope word. My second remark > would not change that (user visible) interface so I think > we can now play with the idea and can clean up the > code behind the scenes with less pressure ;) Hello Matthias, Good, did svn update deciding conflicts in your favor :-) Regarding the behind the scenes cleanup, do you allow merging of XT_HEADER into XT_DOCREATE ? Regards, Enoch. |
From: Matthias T. <mt...@we...> - 2013-03-30 10:14:41
|
Hi Enoch, > Good, did svn update deciding conflicts in your favor :-) ;) > Regarding the behind the scenes cleanup, do you allow merging of > XT_HEADER into XT_DOCREATE ? No. HEADER is useful for other things too. I think more of something like CREATE -> SCOPE -> HEADER -> . something completely different like : ... -> REVEAL (bascially the lonly !E's in your patch are called REVEAL in other forth's) This covers the SMUDGE in : and ; as well. ---------- more unrelated stuff ------------ What about word changes? What if can_foo is placed into the can wordlist *and* changes the wordlist entry name to foo only? Together with a recognizer that puzzles the pieces together again, if needed. Another idea is to organize the scopes like the recognizers as a stack. They can be called in order and the final default action is to place the new word in CURRENT. And I found this posting worth reading http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.forth/2011-01/msg00201.html Matthias |
From: Enoch <ix...@ho...> - 2013-03-31 14:41:11
|
Hello Matthias, Having given further thought to r1404 and your recent comments I think that we need to revert to the wlscope former interface to utilize this new mechanism to its fullest. Example follows and here's the kernel patch: http://pastebin.com/aSWRMU3V Regards, Enoch. \ wlscope, "wordlist scope" ( addr len -- addr' len' wid ), is a deferred word \ which enables the AmForth application to choose the wordlist ( wid ) for the \ new voc entry based on the input ( addr len ) string. The name of the new voc \ entry ( addr' len' ) may be different from the input string. Note that *all* \ created voc entry types pass through the wlscope mechanism. The default \ wlscope action passes the input string to the output without modification and \ uses get-current to select the wid. \ The following example shows how to create a library of words under a special \ wordlist (can_lib). This example also shows how to chain scope calls safely. wordlist constant can_lib get-order 1+ can_lib swap set-order \ can_lib would be searched first : can_scope ( addr len -- addr' len' wid ) 2dup 4 > if \ name length check s" can_" tuck icompare if \ name prefix check 4 - swap 4 + swap \ drop prefix from created word can_lib exit then else drop then [ ' wlscope defer@ ] literal execute ; ' can_scope is wlscope |