Hi Eric,

Thanks for being so helpful.
My larger goal (and I understand there are others working on this too) is a 
lisp-looking syntax for julia. 
I'd like to be able to use Julia's inbuilt macro mechanisms to basically 
macroexpand a clojure-looking file of code

I can write

(defmacro m [x] '(if ~x 1 0)) 
(defn f [x] (@m x)) 

and get

macro m(x)
  :($x ? 1 : 0)
end

function f(x) @m x end

then also macro expand the module, so

macro m(x)
  :(if $x 1 0)
end 

function f(x) x ? 1 : 0 end

and then convert it back, so i get

(defn f [x] (if x 1 0)) 

In that case, I'd be able to use julia as the macroexpander in a process 
that then can use wisp.js and the like to port everything to js, or hy to 
port to python, etc. 
There's really no "need" to do this (can just use cljs or just write js 
directly for any actual purpose), but I wanted to do some learning about 
transpilers/macro systems and quoting issues and figured this would be a 
fun learning project. I also wanted to learn julia and about julia, so it's 
been very good for that too.

You can see what's going on here:
https://github.com/vshesh/Sexpr.jl 

The idea about stringifying expressions comes from the fact that I'm trying 
to write all the modules to file first, so that they all exist if they 
import symbols from each other (and so I can macro expand them 
individually). 

this particular issue is showing up because there are reserved words in 
julia that you can't just print out/stringify and expect to parse back.

Eg for the macro example above, you end up with (if, true, 1, 0) as the 
form you're returning. Of course, the parser chokes on an empty if followed 
by a comma, so the solution is to quote it, and get  (:if, true, 1, 0) 
(quote of a constant = constant). Now I'd need to unquote stuff on the way 
out after the macro returns something.... 
I'm not even sure I'm asking the right questions here; there's a chance 
I've set up the whole thing the wrong way, but I'm pretty sure it's 
necessary to translate the forms returned by the macro back into julia 
(since they come out as s-expressions) and that's where the current two 
questions are coming from.

Thank you!
Vishesh


On Friday, April 1, 2016 at 6:37:34 PM UTC-7, Eric Forgy wrote:
>
> Hi Visesh,
>
> I'm interested in your questions and they are similar to things I've 
> struggled with, but I can't help much so I hope someone else can.
>
> BUT... I wonder if you can explain a bit more about what is the big 
> picture you are trying to achieve? It feels to me that you are trying to do 
> something slightly un-Julian. If you explain the big picture of what you're 
> trying to achieve, I suspect someone here can help you find a clean Julian 
> way to achieve it.
>
> So far, your questions are clear, focused and concise, but without a 
> bigger context, I suspect some experts here are unsure how to help although 
> they could probably suggest a cleaner approach.
>
> It sounds like you want to read an expression for a file? Is that right? 
> If so, that doesn't "feel" right to me.
>
> In any case, good luck and welcome to Julia :)
>
> Best regards,
> Eric
>
> On Saturday, April 2, 2016 at 8:56:48 AM UTC+8, [email protected] wrote:
>>
>> oh wait, is it eval?
>>
>> eval(:(:x)) -> :x?
>>
>> On Friday, April 1, 2016 at 5:52:42 PM UTC-7, [email protected] wrote:
>>>
>>> > x = :(:x)
>>> > $x
>>>
>>> *ERROR: unsupported or misplaced expression $*
>>>
>>>
>>> Is there a quote/unquote function that mimics the behavior or what 
>>> happens when you wrap something with :() or do $x? I want to retrieve 
>>> what's inside the variable x's expression.
>>>
>>> It's not sufficient to just wrap in Expr(:quote, ...) since that's not 
>>> the same as :() and similarly I can't find any documentation on how to 
>>> unquote something.
>>>
>>> There must be some routine being called in order to do the 
>>> quoting/unquoting - is there a way to access it?
>>>
>>>
>>> Vishesh
>>>
>>

Reply via email to