Shop OBEX P1 Docs P2 Docs Learn Events
Forthers - Can you really work well this way? - Page 3 — Parallax Forums

Forthers - Can you really work well this way?

13»

Comments

  • prof_brainoprof_braino Posts: 4,313
    edited 2012-11-18 10:29
    I am trying to just accept that the CREATE ... DOES> ....

    As answered in the other thread - What do you want to define? You will see how it works once you work through an example.

    From the propforth command line, type words

    The displays shows for each word in the dictionary its address, some combination of FIAX and the words name,. I believe these are the flags Dave is talking about.

    F =forth word
    I=immediate word
    A=assembler word
    X=compile time word (executes at compile time)

    Everything forth needs to do, propforth does. The functionality you are looking for for CREATE...DOES> already is implemented and is in use, but its done slightly differently, so different words are used, and the actual steps are a little different, but in essence the same stuff is made to happen when it needs to happen.

    You are asking a very advanced question, but I don't think you (as a beginner) understand what you are asking, so the answer is not making sense. New answer: You are very worried about a non issue. Relax! You'll get there, don't rush.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-11-18 11:57
    prof_braino, as an example, how would PropForth implement the ARRAY word that is described in "Starting Forth" as follows?
    : ARRAY ( #rows #cols -- ) CREATE DUP , * ALLOT
      DOES> ( member: row col -- addr ) ROT OVER @ * + +  CELL+ ;
    
    To create an array four bytes by four bytes, we would say
        4 4 ARRAY BOARD
    
    To access, say, the byte in row 2, column 1, we could say
        2 1 BOARD C@
    
    One way to do this is to define two separate words -- one for declaring an array, and another for accessing it. I assume that's how you would do it in PropForth, correct?
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-11-18 16:24
    Dave Hein wrote: »
    prof_braino, as an example, how would PropForth implement the ARRAY word that is described in "Starting Forth" as follows?
    : ARRAY ( #rows #cols -- ) CREATE DUP , * ALLOT
      DOES> ( member: row col -- addr ) ROT OVER @ * + +  CELL+ ;
    
    To create an array four bytes by four bytes, we would say
        4 4 ARRAY BOARD
    
    To access, say, the byte in row 2, column 1, we could say
        2 1 BOARD C@
    
    One way to do this is to define two separate words -- one for declaring an array, and another for accessing it. I assume that's how you would do it in PropForth, correct?

    Yes
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-19 04:12
    As answered in the other thread - What do you want to define? You will see how it works once you work through an example.

    From the propforth command line, type words

    The displays shows for each word in the dictionary its address, some combination of FIAX and the words name,. I believe these are the flags Dave is talking about.

    F =forth word
    I=immediate word
    A=assembler word
    X=compile time word (executes at compile time)

    Everything forth needs to do, propforth does. The functionality you are looking for for CREATE...DOES> already is implemented and is in use, but its done slightly differently, so different words are used, and the actual steps are a little different, but in essence the same stuff is made to happen when it needs to happen.

    You are asking a very advanced question, but I don't think you (as a beginner) understand what you are asking, so the answer is not making sense. New answer: You are very worried about a non issue. Relax! You'll get there, don't rush.

    Yes, I know this a rather an advanced issue. I did not understand the F I A X notation as I haven't found documentation to what that means. I am beginning to understand it as being indicators of the 3 flag bits in the first byte of a Forth word's dictionary entry.

    The simple reality is that I am reading several mainstream Forth presentations, and the PropForth documents at the same time. I tend to think that the PropForth documents are adequate for a beginner to get up and running, but once one is at an intermediate level - they may have to dig up facts on their own.

    On the one hand, you say the user can create a complete Forth; on the other hand, the specifics of how to do so are left to the user to dig out. I am just building a path way for myself and others.

    Have you noticed that when I bring up some of these issues, new faces appear wanting to know more. That is real growth in the user community. Welcome to all.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-11-19 05:08
    I did not under the F I A X notation as I haven't found documentation to what that means. I am beginning to understand it as being indicators of the 3 flag bits in the first byte of a Forth word's dictionary entry.

    Me too, I asked Sal to explain it, and he said he though he fully documented that in the comments in the code when he wrote it. (Which is what we should be looking at to see how anything works). Sure enough, there it was, as always. Now that stuff has been optimized, its another step to dig back to the pre-optimized, high level forth code; but this is exactly what somebody wanting to know about this want to do. So the issue is getting us used to the notion that the PDF and/or wiki and/or htm is the first step in the docs, and the source code is the second step. This method has risk, I've seen this method turn out badly when the comments are ommitted or out of date,; but Sal is pretty thorough in all cases so far, so I think maybe we can rely him.
    The simple reality is that I am reading several mainstream Forth presentations, and the PropForth documents at the same time. I tend to think that the PropForth documents are adequate for a beginner to get up and running, but once one is at an intermediate level - they may have to dig up facts on their own.On the one hand, you say the user can create a complete Forth; on the other hand, the specifics of how to do so are left to the user to dig out. I am just building a path way for myself and others.

    This is a good idea. Some folks have mentions that it appears we only "argue" about what constitutes forth. I suspect in reality those folks have never had to experience the extra effort of proper documentation, suitable for an absolute beginner. It very rare to get and actual teacher involved on any project, let alone such and obscure effort as propforth.
    Have you noticed that when I bring up some of these issues, new faces appear wanting to know more. That is real growth in the user community. Welcome to all.

    Yes, this is the goal. If we could just get a few more newcomers asking questions about function (rather than what constitutes a 'real' forth), and entice a few more wizards to start answering... folks would have one more cool tool in the tool box. And more options how to use their rigs.
  • MJBMJB Posts: 1,235
    edited 2012-11-19 05:59
    Dave Hein wrote: »
    prof_braino, as an example, how would PropForth implement the ARRAY word that is described in "Starting Forth" as follows?
    : ARRAY ( #rows #cols -- ) CREATE DUP , * ALLOT
      DOES> ( member: row col -- addr ) ROT OVER @ * + +  CELL+ ;
    
    
    To create an array four bytes by four bytes, we would say
    
    
        4 4 ARRAY BOARD
    
    
    To access the byte in row 2, column 1, we could say
    
      
        2 1 BOARD C@
    
      
    
    
    One way to do this is to define two separate words -- one for declaring an array, and another for accessing it. I assume that's how you would do it in PropForth, correct?

    can we make it concrete?
    so the two words would be:
    : DEFARRAY ( #rows #cols -- ) CREATE DUP , * ALLOT ;
    : ARRAYPTR ( member: row col -- addr ) ROT OVER @ * + +  CELL+ ;
    
    and optionally
    : ARRAY@   (  addr )  ARRAYPTR C@ ;
    : ARRAY!     ( n addr )  ARRAYPTR C! ;
    
    
    To create an array four bytes by four bytes, we would say    
    
     4 4 DEFARRAY BOARD  
    
    To access the byte in row 2, column 1, we could say    
    
     2 1 BOARD ARRAY@
    
    and to store value
    
    value 2 1 BOARD ARRAY!
    

    The created array will return it's pointer when the arrayname word is used. And the functionality is implemented in the array accessor word.

    is this what you mean?

    I still can't see how this approach would help in the case of my DEFcmd where I want the defined command to exhibit the wanted behaviour and not a separate word.
    So at compile time a pointer to the runtime code needs to be placed somewhere - in the dictionary ??
    Aparrently here my understanding is not complete.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-19 06:00
    @Prof Braino
    "The PDF and/or wiki"? There are an awful lot of wikis. This reads like a lawyer saying it is in that 20 pages of fine print.............

    If you know where something is provide a Wiki title or a section number of the HTML. After all you want people to use the resources available and not abandon the project.

    I suspect that you are weary of us having to ask you directly, but we are rather helpless against vague repies.

    Maybe....................JUST maybe, the html should be converted to a complete PDF so that we could do our own keyword searches and not bother you.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-11-19 06:49
    MJB, your examples help to clarify how the ARRAY word would work. I think it's reasonable for a Forth interpreter to not implement DOES>. It won't conform to the ANS standard, and it makes it harder to port code. However, if portability is not required, then the functionality of DOES> can be implemented in another way.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-19 08:56
    I just keep wondering what the real advantages of the other way are == more speed, less code?
  • MJBMJB Posts: 1,235
    edited 2012-11-19 11:44
    more on CREATE ... DOES> the pearl of FORTH ...
    just found this - while I am studying it you can also have a look.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-19 12:26
    MJB wrote: »
    more on CREATE ... DOES> the pearl of FORTH ...
    just found this - while I am studying it you can also have a look.

    Yes, a few people have gotten to this before you. Thus, the heated debate.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-19 12:30
    MJB wrote: »

    Thank you. You might also enjoy visiting Forthfreaks. http://www.forthfreak.net/index.cgi?
    But be careful, you can get buried in a lot of distracting reading.

    A beginner's guide to Forth is extremely useful.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-11-19 13:34
    "The PDF and/or wiki"? There are an awful lot of wikis. This reads like a lawyer saying it is in that 20 pages of fine print.............

    Yes, the wiki pages are mostly horrible. I thought I could organize them, but it didn't work. I should go and delete them, but I don't which is the one folks actually read.
    If you know where something is provide a Wiki title or a section number of the HTML.

    Please add any references or re-organization as you see fit.
    I suspect that you are weary of us having to ask you directly, but we are rather helpless against vague replies.

    Not at all, the doc are to be driven by the user questions. This is the experiment we undertook, and I fully intend to continue with it until relieved. If you get an answer that doesn't work, ask again. Sooner or later it will stick. I actually can't tell if my replies are vague, they seem wordy to me.
    maybe, the html should be converted to a complete PDF so that we could do our own keyword searches and not bother you.

    I just do searches right in firefox, works great. Sal uses some weird doc editor, so he converts it to html for our convenience. I don't know everybody's editor, but I know everybody has a browser. You can convert it to what ever format works best for you.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-11-19 13:56
    MJB wrote: »
    c....is this what you mean?

    Pretty much, but I don't have my rig in front of me, and I don't need arrays so often, so I can't give good example off the top of my head. I usually don't do a defining word, I just do the definition. Then I make a word that executes on the array.

    I can't really see what your trying to do. Here is a suggestion? Have you looked at Hive-project.de?

    drone235 wrote a version of forth for the prop, he calls it M i think, like that Peter Lori movie. Anyway, he's really sharp, and he's really nice, I bet he and his crew could help you out. They know about all propforth and Tachyon, give them a shout.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-20 03:44
    I have Firefox installed, but no text search feature. And so I suggested the .pdf conversion that has a FIND function for me. I have several alternatives for DIY -- create my own PDF image in Libre Office (very easy to do, but the Logic Analyser images disappear), open the .htm in Libre Office and do searches (also easy to do, but there is a danger of corrupting the file), and I guess I could locate a FIND add-on for Firefox.

    I may not do much with all these questions untll after Thanksgiving as Parallax is having a Forth Contest and it is about time to just work with what I have learned.
  • MJBMJB Posts: 1,235
    edited 2012-11-20 03:49
    in my - standard - FIREFOX I just type control-F for find
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-20 03:57
    MJB wrote: »
    can we make it concrete?
    so the two words would be:
    : DEFARRAY ( #rows #cols -- ) CREATE DUP , * ALLOT ;
    : ARRAYPTR ( member: row col -- addr ) ROT OVER @ * + +  CELL+ ;
    
    and optionally
    : ARRAY@   (  addr )  ARRAYPTR C@ ;
    : ARRAY!     ( n addr )  ARRAYPTR C! ;
    
    
    To create an array four bytes by four bytes, we would say    
    
     4 4 DEFARRAY BOARD  
    
    To access the byte in row 2, column 1, we could say    
    
     2 1 BOARD ARRAY@
    
    and to store value
    
    value 2 1 BOARD ARRAY!
    

    The created array will return it's pointer when the arrayname word is used. And the functionality is implemented in the array accessor word.

    is this what you mean?

    I still can't see how this approach would help in the case of my DEFcmd where I want the defined command to exhibit the wanted behaviour and not a separate word.
    So at compile time a pointer to the runtime code needs to be placed somewhere - in the dictionary ??
    Aparrently here my understanding is not complete.

    There is a wiki about the dictionary construct and there are indeed 3 flags. You will have to investigate and verify that the flags are the same as typical Forth flags as they are named a bit oddly and there is just the $080, $040, and $020 associated with them to indicate which does what when high or low.

    http://code.google.com/p/propforth/wiki/PropForthDictionaryStructure

    Typical Forth has 3 flags that are State, Immediate, and Hidden
    State is an execute/compile toggle
    Immediate is an immediate/not immediate toggle
    Hidden is a toggle that creates :noname Forth words. This is a bit new to me.

    But on PropForth, we have a different listing Execute, Immediate, and Forth.

    I suspect they are the same, but just have rather silly differences in name.

    PropForth seems to be lacking several needed words for what you desire. The [ or (left bracket) does not exist and neither does the , or (comma). Mr. Noble's book, 'A beginner's guide to Forth' should be at least partially helpful to work through this.

    And there are words like STATE that are supposed to exist to indicate what the flag is doing... maybe it is a useful entry to manipulate the flag as well.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-20 12:03
    @MJB
    I have tried to figure out how I might create all the features that I found in "Starting Forth"

    You know about "A beginner's guide to Forth" by Noble, and that is helpful.
    But Chapter 11 in "Starting Forth" by Brodie might allow you to create a CREATE and DOES> that behave the way you want.
    And then there is the Wikipedia entry on Forth in English that explains the Dictionary entry and the use of the 3 flags.

    About the only other thing I can consider helpful is Dave Hein has written - pfth - his ANS Forth for the Propeller in C and if you can read C, it may help with defining some missing words in Forth. I am not sure if all the words are written in C or if quite a few are just provided in Forth to be compiled in Forth.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-11-20 12:32
    There is a wiki about the dictionary construct
    http://code.google.com/p/propforth/wiki/PropForthDictionaryStructure
    ...
    And there are words like STATE that are supposed to exist to indicate what the flag is doing... maybe it is a useful entry to manipulate the flag as well.

    Please notice that the referenced wiki page is tagged for version 2.7, do not rely on this to be up to date for version 5.x. Any page tagged with less than the current release has not been updated.

    Please instead refer to Propforth.htm in the download archive. See:

    9.1.305 state

    in propforth.htm for the comments regarding the word state.

    Notice that the explanation for each word looks like comments pulled directly from the source code. I think they are, Sal generates the doc directly from the source code text. (Neat idea, huh? I wonder if it works....) If we need further explanation, we are to trace through the actual code to see what it does.

    Also notice that there is nothing filled in for words then, if, loop. We need someone to explain these in terms a beginner can understand. (Or explain that these cannot be explained yet, or point to a further reference, etc)

    For lockdict, please refer to 7.2 Writing Assembler Words.
    Notice this is an advanced topic. This correctly uses the propforth word CREATE. You have to ask caskaz for anything more on this as I have not played with this yet. (although it looks pretty cool, when i catch up....)
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-11-21 09:58
    Lockdict and Freedict are paired opposites. I see what is going on now as I have not devoted very much time to Section 7 as I am not adept at PASM.

    The listings in Section 9 become a blur without functional breakout, which you asked me to do. ALL of the locks might be collected under one major heading and a few subheadings to identify their different reasons for existing.

    Long lists may be useful to verify an item is included, but they really are difficult to study. Groups that associate are much more helpful. I have had several false starts as I keep learning more as I try to group these things.

    In other words, both kinds of list are important to managing a lexicon. Nobody really learns much by just reading a dictionary, they need see how words work together. The brain actually retains more through association that through rote memorization.

    ~~~~~~~~~~~~~~~~~~~~~

    I now see that the Dictionary Structure wiki is V2.7, but it is a point of departure. Such a key topic is related to the functioning of Forth words, so a V5.0 or later revision might be useful. I'd have to spend some time investigating to confirm what is still what and what is changed. I guess anybody would unless there is a rigorous change log.

    ~~~~~~~~~~~~~~~~~~~~~
    Investigation complete.!!!
    The Dictionary Structure is written into the .spin file for whatever kernel one is using and the notes therein pretty much confirm that the approach in V2.7 is still being used. AND, it definitely clarifies that the 3 flags are not entirely the same as what older Forths have used. The Forth flag is a toggle between Forth words and Assembly words in lieu of flag for Hidden words versus Not hidden .

    At this point I have no idea what the implications are, but I am beginning to see that I have to use the source much more intensively. Also I have to sort out have the concept of Hidden words is, what the concept of Assembler words is, and what is the pro and con of each one.

    In other words, it is time for me to actually apply what little knowledge I have of both Forth and PASM to the actual code. After all, if it works correctly - it is the best documentation provided. If it doesn't work right, you need to wade in and find a way to fix it.
Sign In or Register to comment.