<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Firstly many thanks for the explanation of the use of "literal-id" in macros.<br><br>As a simple exercise in learning how to use Racket macros, I'm trying to simulate using C style array indices syntax in accessing nested Racket vectors.<br><br>I'm able to set up a macro to access a nexted Racket vector using a syntax like: (array-ref v3[0 1 2] )<br><br>(define v #( #(1 2 3) #(11 22 33) #(111 222 333)))<br>(define v1 #( #(4 5 6) #(44 55 66) #(444 555 666)))<br>(define v3 (vector v v1))<br><br>(define-syntax array-ref<br> (syntax-rules ()<br> [(array-ref v [d1]) (vector-ref v d1)]<br> [(array-ref v [d1 d2 ... ]) (array-ref (vector-ref v d1) [d2 ... ])]))<br><br>I can set up a macro to access a two-dimensional vector with a syntax like (array-ref1 v[0,1])<br>(define-syntax array-ref1<br> (syntax-rules ()<br> [(array-ref1 v [d1]) (vector-ref v d1)]<br> [(array-ref1 v [d1 , d2 ]) (array-ref1 (array-ref1 v [d1]) [ d2 ])]))<br><br>But when I do the following <br>(define-syntax array-ref1<br> (syntax-rules ()<br> [(array-ref1 v [d1]) (vector-ref v d1)]<br> [(array-ref1 v [d1 , d2 ]) (array-ref1 (array-ref1 v [d1]) [ d2 ])]<br> [(array-ref v [d1 , d2 , d3]) (array-ref (array-ref (array-ref v [d1]) [d2]) [d3])]))<br><br>I get this error:<br> syntax-rules: variable used twice in pattern in: unquote<br><br>Putting a comma as a literal-id doesn't help, it gives the error <br>Module Language: invalid module text<br>. read: unexpected `)'<br><br>Ideally I'd like to be able to set up a macro that can access any level of nested vectors. <br>I.e. how do I show in the pattern that I want to repeat not just a pattern variable but ", pattern variable".<br><br>Many thanks,<br>Harry Spier<br>                                            </div></body>
</html>