On Wed, Nov 10, 2010 at 4:51 PM, Shaping <shap...@charter.net> wrote:
> If I want general-to-particular reading order, must I define a parsing word
> of my own?
>
>  -b/2a  <:  b negated a/2 *

Defining a <: operator with that exact syntax is not possible. For
one, in Factor, new symbol names can only be created as part of syntax
forms, and so must come after a syntax word of some sort. The new name
"-b/2a" in this case comes before the <: syntax word. The other
problem is that you need some way to indicate where the expression
whose value is being bound ends.

You could, however, define a form with explicit opening and closing
tokens, for example:

[set -b/2a := b negated a/2 * ]

The definition for "[set" would look something like this:

--
SYNTAX: [set
    scan locals get parse-def ! scan a token and parse it as a locals binding
    ":=" expect ! scan a token and raise an error if it's not ":="
    \ ] parse-until ! scan and parse objects until the "]" word is parsed
    swap suffix! append! ;
    ! append first the expression body, then the local definition to
the parser accumulator
    ! as if it had appeared as "expression :> name"

:: foo ( x y -- z ) [set z := x y + ] z ;
--

-Joe

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to