Re: [julia-users] local types or macros?

2016-04-13 Thread Stefan Karpinski
To answer somewhat the reason for the lack of local macros: Julia relies on
macros considerably less than Lisp does. In fact, they're generally seen as
a last resort. From this perspective, there's not so much call for local
macros. There are, of course, namespace-local macros, which seems
sufficient.

On Wed, Apr 13, 2016 at 8:13 AM, Tamas Papp  wrote:

>
> On Wed, Apr 13 2016, Didier Verna wrote:
>
> > Tamas Papp  wrote:
> >
> >> My perception is that simply pointing out that something is different
> >> in Common Lisp is unlikely to move the Julia language team to make
> >> fundamental changes to the language
> >
> >   ... which is not my intention. I'm simply curious about the language,
> >   and when I see something different from what I'm used to or which
> >   surprises me, I'm asking questions to get a better understanding.
> >
> >   Is all ;-)
>
> Once you are familiar with the language, it would be great if you would
> consider writing some blog posts or tutorials about macros in Julia from
> a Lisper perspective. I have been ignoring them almost completely for
> now, exploring other powerful features (expecially the possibilities of
> the rich type system).
>
> Best,
>
> Tamas
>


Re: [julia-users] local types or macros?

2016-04-13 Thread Tamas Papp

On Wed, Apr 13 2016, Didier Verna wrote:

> Tamas Papp  wrote:
>
>> My perception is that simply pointing out that something is different
>> in Common Lisp is unlikely to move the Julia language team to make
>> fundamental changes to the language
>
>   ... which is not my intention. I'm simply curious about the language,
>   and when I see something different from what I'm used to or which
>   surprises me, I'm asking questions to get a better understanding.
>
>   Is all ;-)

Once you are familiar with the language, it would be great if you would
consider writing some blog posts or tutorials about macros in Julia from
a Lisper perspective. I have been ignoring them almost completely for
now, exploring other powerful features (expecially the possibilities of
the rich type system).

Best,

Tamas


Re: [julia-users] local types or macros?

2016-04-13 Thread Didier Verna
Tamas Papp  wrote:

> My perception is that simply pointing out that something is different
> in Common Lisp is unlikely to move the Julia language team to make
> fundamental changes to the language

  ... which is not my intention. I'm simply curious about the language,
  and when I see something different from what I'm used to or which
  surprises me, I'm asking questions to get a better understanding.

  Is all ;-)

-- 
ELS'16 registration open! http://www.european-lisp-symposium.org

Lisp, Jazz, Aïkido: http://www.didierverna.info


Re: [julia-users] local types or macros?

2016-04-13 Thread Tamas Papp
Hi Didier,

It is good to see some familiar names from comp.lang.lisp :D

I switched to Julia from Lisp a while ago, expecting it to be some kind
of Common Lisp with Dylan-like surface syntax, only faster and with
parametric types.

It isn't, and while Common Lisp influenced the design considerably,
Julia made a lot of different choices, most of them consciously: either
to make the language more familiar for people migrating from
Matlab/R/etc, or to make it easier to optimize, or just because they
liked it that way.

My perception is that simply pointing out that something is different in
Common Lisp is unlikely to move the Julia language team to make
fundamental changes to the language, or even to introduce new
constructs. On the other hand, from reading the discussions on the issue
tracker, it seems that well thought-out examples of real-world problems,
especially if they come with a suggestion for a solution, are more
likely to get sympathetic attention.

So if you use Julia for a while and feel that it should have a construct
equivalent to macrolet, maybe you could write up a detailed proposal,
with code examples from Base or libraries, and how it would simplify
things.

Best,

Tamas

On Wed, Apr 13 2016, Didier Verna wrote:

> Cedric St-Jean  wrote:
>
>> Local macros in Lisp are expanded at compile-time. They're useful
>> inside macro-expansions, eg.
>
> Not even inside other macros, but as local macros inside any kind of
> code block. E.g. (silly):
>
> CL-USER> (let (list)
>  (macrolet ((add (element) `(push ,element list)))
>(add 3)
>(add 2)
>(add 1)))
> (1 2 3)
> CL-USER> 



Re: [julia-users] local types or macros?

2016-04-13 Thread Didier Verna
Cedric St-Jean  wrote:

> Local macros in Lisp are expanded at compile-time. They're useful
> inside macro-expansions, eg.

Not even inside other macros, but as local macros inside any kind of
code block. E.g. (silly):

CL-USER> (let (list)
   (macrolet ((add (element) `(push ,element list)))
 (add 3)
 (add 2)
 (add 1)))
(1 2 3)
CL-USER> 

-- 
ELS'16 registration open! http://www.european-lisp-symposium.org

Lisp, Jazz, Aïkido: http://www.didierverna.info


Re: [julia-users] local types or macros?

2016-04-12 Thread Cedric St-Jean
On Tue, Apr 12, 2016 at 9:25 AM, Yichao Yu  wrote:

> On Tue, Apr 12, 2016 at 9:18 AM, Cedric St-Jean 
> wrote:
> >
> >
> > On Tuesday, April 12, 2016 at 8:59:54 AM UTC-4, Yichao Yu wrote:
> >>
> >>
> >> Macros cannot be scope local (without major change of everything)
> >> since they are executed at compile time and doesn't know anything in
> >> the scope.
> >
> >
> > Local macros in Lisp are expanded at compile-time. They're useful inside
> > macro-expansions, eg.
> >
> > @define_model() begin
> > @var x = 10   # @var is a local macro, whose expansion depends on the
> > @define_model arguments
> > end
> >
> > I don't see why Julia couldn't support that.
>
> I don't really know how it works in lisp but in julia a macro is just
> a function with a special name `@...` that can be called automatically
> called by the parser.
>

Same in Lisp


> Also note that macros are not expanded when passing to another macro
> so if that is what you want, you can search for macrocalls in the AST
> you get in the macro and replace them when expressions you want.
>

True, but that's a pretty gruesome task for arbitrary ASTs. I just googled
"code-walker Julia" and didn't get any results. macrolet is a lot cleaner.


>
> >
> >>
> >>
> >> >
> >> > Thanks.
> >> >
> >> > --
> >> > ELS'16 registration open! http://www.european-lisp-symposium.org
> >> >
> >> > Lisp, Jazz, Aïkido: http://www.didierverna.info
>


Re: [julia-users] local types or macros?

2016-04-12 Thread Yichao Yu
On Tue, Apr 12, 2016 at 9:18 AM, Cedric St-Jean  wrote:
>
>
> On Tuesday, April 12, 2016 at 8:59:54 AM UTC-4, Yichao Yu wrote:
>>
>>
>> Macros cannot be scope local (without major change of everything)
>> since they are executed at compile time and doesn't know anything in
>> the scope.
>
>
> Local macros in Lisp are expanded at compile-time. They're useful inside
> macro-expansions, eg.
>
> @define_model() begin
> @var x = 10   # @var is a local macro, whose expansion depends on the
> @define_model arguments
> end
>
> I don't see why Julia couldn't support that.

I don't really know how it works in lisp but in julia a macro is just
a function with a special name `@...` that can be called automatically
called by the parser.

Also note that macros are not expanded when passing to another macro
so if that is what you want, you can search for macrocalls in the AST
you get in the macro and replace them when expressions you want.

>
>>
>>
>> >
>> > Thanks.
>> >
>> > --
>> > ELS'16 registration open! http://www.european-lisp-symposium.org
>> >
>> > Lisp, Jazz, Aïkido: http://www.didierverna.info


Re: [julia-users] local types or macros?

2016-04-12 Thread Cedric St-Jean


On Tuesday, April 12, 2016 at 8:59:54 AM UTC-4, Yichao Yu wrote:
>
>
> Macros cannot be scope local (without major change of everything) 
> since they are executed at compile time and doesn't know anything in 
> the scope. 
>

Local macros in Lisp are expanded at compile-time. They're useful inside 
macro-expansions, eg.

@define_model() begin
@var x = 10   # @var is a local macro, whose expansion depends on the 
@define_model arguments
end

I don't see why Julia couldn't support that.
 

>
> > 
> > Thanks. 
> > 
> > -- 
> > ELS'16 registration open! http://www.european-lisp-symposium.org 
> > 
> > Lisp, Jazz, Aïkido: http://www.didierverna.info 
>


Re: [julia-users] local types or macros?

2016-04-12 Thread Yichao Yu
On Tue, Apr 12, 2016 at 5:18 AM, Didier Verna  wrote:
>
>   What's the reason for restricting types and macros to the toplevel?
>   Isn't there something like macrolet?

For types, it will be much harder for the compiler to infer anything
about it, if a new type is to be created every time. And if you want a
new type every time you run the code (in a local scope), you should
just use `eval`, which doesn't require special compiler support and is
just as fast/slow.
"anonymous" types, i.e. types you can create instance of that doesn't
require declaring explicitly is support in the form of anonymous
functions on 0.5, similar to how lambda is implemented in c++11.
Tuples are similar too.

Macros cannot be scope local (without major change of everything)
since they are executed at compile time and doesn't know anything in
the scope.

>
> Thanks.
>
> --
> ELS'16 registration open! http://www.european-lisp-symposium.org
>
> Lisp, Jazz, Aïkido: http://www.didierverna.info


[julia-users] local types or macros?

2016-04-12 Thread Didier Verna

  What's the reason for restricting types and macros to the toplevel?
  Isn't there something like macrolet?

Thanks.

-- 
ELS'16 registration open! http://www.european-lisp-symposium.org

Lisp, Jazz, Aïkido: http://www.didierverna.info