home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,062 of 117,927   
   Paul Rubin to dxf   
   Re: quotations   
   09 Feb 25 02:36:04   
   
   From: no.email@nospam.invalid   
      
   dxf  writes:   
   > IMO it does nothing for readability to see a definition interrupted by   
   > another.  My reaction is one of WTF.   
      
   Maybe it looks weird in Forth, but similar things were present in   
   languages as old as Fortran, which had "statement functions" (idk when   
   those were introduced though).  Algol had them, and lambda calculus   
   (invented in the 1920's, before computers existed) had them.  It's not   
   inherently bad, though it can make code confusing if over-used.  node.js   
   uses the style heavily in a deeply nested and painful way.   
      
   >>    : make-action ( n -- xt ) [n:d ." You pressed " . ] ;   
   > I don't understand make-action at all.  What is it meant to be doing?   
      
   Imagine this function:   
      
     : action-5 ( -- ) ." you pressed 5" ;   
      
   That does the obvious thing: prints a fixed message, nothing else.   
   Similarly you want action-1, action-2, and so on.   
      
   How to generalize that?  How about just having something that takes   
   a numeric argument, and gives you an xt that runs that action?   
      
     : make-action-n ( n -- xt )  ( need some magic here! )  ... ;   
      
   So, "5 make-action-n" gives an xt that is equivalent to ' action-5,   
   but you can make independent xt's for other values of n.   
      
   That's what I called make-action in the example I showed, and for the   
   "magic" it used a quotation.  Maybe there is some reasonably easy   
   alternative way to do the same thing in traditional Forth.  The only   
   ones that occur to me right now are pretty messy though.   
      
   > Call me boring but I don't like inventing new syntax only to have to   
      
   Well, it's a one-time addition of new syntax, not something re-learned   
   in every new program.  Like 'x' is new syntax for [char] x, but once   
   you've used it a few times you remember it and it seems to me like an   
   improvement.   
      
   So are quotations worth it for Forth?  I don't know.  I see some uses   
   for them but I'd tend to say that style is more common in GC'd   
   languages.   
      
   > the antithesis of Forth - the opposite of being simple.   
      
   Forth is simple in some ways, complicated (or at least non-intuitive) in   
   others ;).   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca