pattern variable coercion 
Author Message
 pattern variable coercion

While reading "Dylan Programming" I stumbled over coercion of pattern
variables. (page 368)

Here is a contrived example:

define macro symbolize
 { symbolize(?:name) } => { ?#"name" }
end macro symbolize;

I could not derive this syntax from the BNF in the DRM. Is this a
Harlequinism?

If yes, I wonder how it could be accomplished by using DRM syntax only.
Since AFAIK ##-style concatenation preserves the syntactical quality (being
string, symbol or name) of the pattern variable (could not find reference),
this will not work:

define macro symbolizeDRM
 { symbolizeDRM(?:name) } => { #"" ## ?name }
end macro symbolizeDRM;

Am I right?

I regard pattern variable coercion as a rather essential feature.
What coercions are supported? And what is their syntax?

Where is this all documented?

Why did not make coercions their way into the DRM?

Thanks,

    Gabor



Wed, 23 Oct 2002 03:00:00 GMT  
 pattern variable coercion

Quote:

> While reading "Dylan Programming" I stumbled over coercion of pattern
> variables [e.g.,]

> define macro symbolize
>  { symbolize(?:name) } => { ?#"name" }
> end macro symbolize;

> I could not derive this syntax from the BNF in the DRM. Is this a
> Harlequinism?

Nope, it's in the DRM, just not easy to find (like a few other things ;-).
See the production /name-string-or-symbol/, under /substitution/, under
/template-element/.

Quote:
> .. AFAIK ##-style concatenation preserves the syntactical quality (being
> string, symbol or name) ...

Yes, it does -- see the section "Templates" in Chapter 10 of the DRM.

Hope that puts your mind at ease :-)
Hugh



Wed, 23 Oct 2002 03:00:00 GMT  
 pattern variable coercion

Quote:
> While reading "Dylan Programming" I stumbled over coercion of pattern
> variables. (page 368)

> Here is a contrived example:

> define macro symbolize
> { symbolize(?:name) } => { ?#"name" }
> end macro symbolize;

> I could not derive this syntax from the BNF in the DRM. Is this a
> Harlequinism?

It is permitted by the BNF.  Look at substitution on p. 429 of the DRM and
you will see that ? can be followed by NAME, STRING, or SYMBOL.  I grant
you, you couldn't be expected to guess why, though.

[...]

Quote:
> I regard pattern variable coercion as a rather essential feature.
> What coercions are supported? And what is their syntax?

The only supported coercions are to symbol (as above) and to a string (using
?"name").

Quote:
> Where is this all documented?

Perhaps quite obscurely on p. 160 of the DRM, where substitution is
explained.

Quote:
> Why did not make coercions their way into the DRM?

Well they did, if obscurely.  It was my hope that the chapter in DP would be
a little more transparent.


Sun, 27 Oct 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Coercion of variables

2. Pattern to increment an instance variable

3. using variable as a pattern for matching

4. problems pattern matching a variable

5. Variable as regular expression in pattern?

6. awk pattern as a variable with regular expression

7. variable as search-pattern: if ($0 ~ myVar)

8. how to use a shell variable in awk for pattern matching

9. Variable / Array in Pattern

10. variables in a pattern match

11. Using Variables in pattern matches

12. How to use variables for patterns?

 

 
Powered by phpBB® Forum Software