Re: [julia-users] Re: Lack of an explicit return in Julia, heartache or happiness?

2016-05-26 Thread Didier Verna
"'Tobias Knopp' via julia-users"  wrote:

> We are currently talking about the long function form which are
> inherently non-functional since they involve a function body which is
> evaluated step by step.

  Nope. In that particular case, size is what matters ;-). You may
  switch to the long form because you have a lot of code to type,
  regardless of the (purely) functional style, or lack thereof.

  Now consider this (a very frequent idiom, at least in my book[1]),
  even independently from any consideration of purity:

  function long (args...)
let this = that, here = there, etc = and_so_on
   # lots of code here
   # and also here
   # oh, I almost forgot, here as well
   # and BTW, all of this may be pure...
end
  end

Do you find it unintuitive that a function with only one statement like
this one returns this statement's value?  Do you also find it
unintuitive that let returns the value of its last expression, just
because it is long? Because if so, then we'd better make let return
nothing by default...

Or maybe we want even more special cases, like, the long function form
would return nothing by default, except if there is a single block of
code in it, in which case it would return this block's value. But then
again, a toplevel let has no point in returning anything, so maybe let
should return nothing by default, but only at the toplevel? :-D

I'm only half-joking here. Point is, again, DWIM is evil because
everyone is looking at this with a different I (I'm actually quite proud
of that one :-D). Consistency throughout a language is much better and
safer, even if that requires some level of paradigm shift for some
users.


> This is against the nature of a purely functional language. Thus, I
> cannot see how its intuitive from a functional side that the last
> statement within a function body evaluates to a return. A functional
> language has no statements that are successively executed.

  You cannot see it because you're mixing "functional" and "purely
  functional" all over the place. Congratulations, you've just
  discovered one of my secret levels! :-) I believe I have a blog about
  this somewhere, but I cannot put my hands on it.

  Even unintentionally using "functional" to mean "purely functional"
  has always led (and will continue to lead) only to more confusion, and
  this is a serious problem. I've witnessed far too many sterile
  discussions between different communities because of this.

  Functional should only mean 1st class functions, as per Christopher
  Stratchey's definition. Purely functional, then, adds the absence of
  side effets. End of story. This confusion comes from the fact
  (probably) that while you can very well be functional without being
  pure, there's little sense in being pure yet not functional. But
  nevertheless, this is harmful.

  In this discussion, I never talked about purity I think. And I
  continue to claim that from a (non pure) functional perspective,
  returning the last expression of a block/function as the
  block/function's value makes perfect sense, for two reasons:
  1. everything has a value (expressions as opposed to instructions,
 functions as opposed to procedures), 
  2. return is an instruction, not an expression. In functional style,
 values are /stated/, not /returned/.


Footnotes: 
[1]  to the point that Lisp has a special construct () to spare you
let form.

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Re: Lack of an explicit return in Julia, heartache or happiness?

2016-05-26 Thread Didier Verna
"'Tobias Knopp' via julia-users"  wrote:

> No return statement is kind of an explicit indication that the
> function does not return anything.

  No it's not. It may be when you come from the procedural camp; it is
  definitely not when you come from the functional camp. That's the
  problem with multi-paradigm languages, especially those with a
  heterogeneous user base. Nothing will ever be universally "intuitive"
  or "natural".

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Lack of an explicit return in Julia, heartache or happiness?

2016-05-25 Thread Didier Verna
Jeffrey Sarnoff  wrote:

> David, if it reads 'complicated' that is my hiccup. The intent was to
> uncomplicate by letting current and future functions do what one would
> expect.

  Which "one"?  DWIM is evil... ;-)
  
-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Lack of an explicit return in Julia, heartache or happiness?

2016-05-25 Thread Didier Verna
David Anthoff  wrote:

> I like that idea. I think the current behavior is not a huge problem,
> but I often run into a situation where I code up a method that
> modifies something and shouldn’t return anything, and then I forget to
> add a blank return statement at the end (*) and the function returns
> just something arbitrary,

  See it the other way around: in a functional style, there's almost
  always a meaningful value to return. You can simply discard it if
  you're not interested, but if one day you need it, it will already be
  here.


> which can be confusing, especially in interactive sessions a la
> IJulia.

  Then, you're not actually bothered by the fact that a function returns
  a value, but by the fact that an interactive session will print it
  (the P in REPL). This is different.

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Lack of an explicit return in Julia, heartache or happiness?

2016-05-25 Thread Didier Verna
Stefan Karpinski wrote:

> The modification I've occasionally considered would be:
>
> * short-form functions implicitly return their expression value;
> * long-form functions implicitly return `nothing` unless an explicit value is
>   returned.

  What's returned by a function (in a functional context where
  everything is an expression) is a matter of language semantics. If you
  go down that road, you're introducing semantic discrepancies out of
  syntactic context. Consider that you would no longer be able to talk
  about the concept of "function" itself, separate from the way a
  function object was constructed (in other words, you increase the
  porosity of the syntax/semantic membrane). I think this is a bad idea.

  It's traditional in impure functional languages to return the value of
  the last expression from compound statements; the former ones only
  making sense by side-effecting. Lisp has some constructs to allow you
  to return the value of previous sub-expressions instead, and we
  idiomatically use (values) to explicitly indicate intent to return
  nothing.

  I can see why some people may be bitten by accidentally returned
  values and would like to get 'nothing' by default, but in a
  multi-paradigm language like this one, especially when functional is
  prominent, it's not the language that needs to be fixed. It's the
  people ;-). They're simply not programming in a functional style
  enough and they should learn to do so. It's a long-term gain anyway.

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Julia implementation

2016-05-24 Thread Didier Verna
Stefan Karpinski wrote:

> There's something delightful about the fact that in order to change
> the syntax of Julia, you must first prove yourself proficient in a
> language that actively rejects the very concept of fancy syntax.

  :-D :-D :-D

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Re: Getting into macros nightmare!

2016-05-12 Thread Didier Verna
Stefan Karpinski wrote:

> Didier, since you definitely have a better handle on what macro
> hygiene means to someone coming from Lisp, would you consider editing
> that text to clarify that point?

  OK (I think I had another request for an update in the manual
  somewhere else as well).

-- 
ELS'16, May 9-10, Krakow, Poland: http://www.european-lisp-symposium.org

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


Re: [julia-users] Re: Getting into macros nightmare!

2016-05-12 Thread Didier Verna
Ford Ox  wrote:

> I have kinda skipped the hygiene chapter in docs :)

  The docs can unfortunately also be a source of confusion. In that
  particular case, contrary to what it says, the macros in Julia are
  only half-hygienic, and esc is a means to restore hygiene, not
  "violate" it.

-- 
ELS'16, May 9-10, Krakow, Poland: http://www.european-lisp-symposium.org

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


[julia-users] cannot make codespeed

2016-05-08 Thread Didier Verna

  Hello,

I cloned Julia yesterday and could make it, except that I cannot 'make
codespeed' in test/perf. The error message is the following:

[skipping a bunch of warnings]
ERROR: LoadError: LoadError: You must provide the JULIA_FLAVOR environment 
variable identifying this julia build!
 in error(::String) at ./error.jl:21
 in include_from_node1(::String) at ./loading.jl:426 (repeats 2 times)
 in process_options(::Base.JLOptions) at ./client.jl:263
 in _start() at ./client.jl:319
while loading /Users/didier/tmp/julia/test/perf/micro/../perfutil.jl, in 
expression starting on line 14
while loading /Users/didier/tmp/julia/test/perf/micro/perf.jl, in expression 
starting on line 5
make: *** [codespeed] Error 1
zsh: exit 2 make codespeed


What value is expected for JULIA_FLAVOR ?


Also, note that the file README.md in test/perf mentions a website which
does not exist (speed.julialang.org).

Thanks.

-- 
ELS'16, May 9-10, Krakow, Poland: http://www.european-lisp-symposium.org

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


Re: [julia-users] Why does julia use END for block end?

2016-05-07 Thread Didier Verna
Kevin Squire  wrote:

> That said, when it comes to opinions and holy wars, we very much like
> it more peaceful around here.

  That message was a joke, sorry if it was taken too seriously...

-- 
ELS'16, May 9-10, Krakow, Poland: http://www.european-lisp-symposium.org

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


Re: [julia-users] Re: Why does julia use END for block end?

2016-05-07 Thread Didier Verna
DNF  wrote:

> It is very clear and explicit, there is no doubt as to what it means,
> unlike '}' which is way too small and ambiguous (does it mean end of
> block, or end of dict definition, etc.), and just does not jump out at
> you the way it should.

  'end' is extremely verbose, just like 'function', 'global', 'local' etc.

  You are also wrong about the curly brace's ambiguity. If you find it
  ambiguous, that is because you live in a world overflown with
  syntax. You don't need end of blocks or dict definitions to be
  different things. You only really need an end of /expression/. And
  BTW, I have a hard time figuring out why 'end' wouldn't be ambiguous
  while '}' would be, especially since 'end' ends so many different
  things in Julia.

  Finally you are also mistaken about the size (yes, size matters). The
  curly brace isn't too small. It's too big. It's too noisy. See this
  little nasty peak in the middle, on the right? It's aggressive, it's
  impolite, it hurts my eyes.

  No, really, the only 'end' that makes sense, should be soft, discreet,
  gentle, almost invisible, in perfect harmony with the
  Universe. There's only one candidate. It's... the right parenthesis
  ')'.
  
-- 
ELS'16, May 9-10, Krakow, Poland: http://www.european-lisp-symposium.org

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


[julia-users] promotion vs. specialization

2016-04-21 Thread Didier Verna

  This is just an idea from the top of my head, probably wild and maybe
  silly. I haven't given it any serious thought.

Given the existence of the general promotion system (which I like a lot,
along with other things in Julia, such as the functor capabilities), I'm
wondering about automatic specialization.

What I mean is this: suppose you have a type Foo which can be converted
to an Int. Suppose as well that you have a function bar that only works
on Ints. You cannot currently call bar with a Foo, but since Foo is
convertible to an Int, it could make sense that bar() suddenly becomes
an applicable method, with implicit conversion...

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

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


Re: [julia-users] Re: are macros hygienic?

2016-04-20 Thread Didier Verna
Yichao Yu  wrote:

>> julia> macro finish()
>>  :(t)
>>end
>> julia> macroexpand(:(@finish()))
>> :t
>>
>> as expected. BTW, this is not really "global", as the manual says. It
>> really is "outer scope".
>
> This is a bug, (the one I linked). It should be `Main.t` (or whatever
> module that the macro is defined in).

  So you mean that if I do this:

  t = 10
  function foo()
t = 5
@finish()
  end

  I will presently get 5 but when the bug is fixed, I will get 10 (or
  whatever value t had in the macro definition's module) ?


> This should be `bar(Main.t)`. use as function argument name is talking
> about defining a function.

  Oh, right. Thanks.

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

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


Re: [julia-users] Re: are macros hygienic?

2016-04-20 Thread Didier Verna
Yichao Yu  wrote:

>>> julia> macro finish()
>>>  t = 5
>>>end

>> Your macro is also simply returning a `5` btw.

Sorry, I meant :(t = 5).


> Just to be clear, the behavior you observer is correct and expected.
> Non-escaped variables used in macro is not supposed to affect the user
> of the macro. The bug report I pasted is merely a FYI since you are
> getting very closed to discover it.

  Right :-) There's still something I'm not sure about. The manual says:
  "A variable is considered local if it is assigned to (and not declared
  global), declared local, or used as a function argument name."

So:

julia> macro finish()
 :(t)
   end
julia> macroexpand(:(@finish()))
:t

as expected. BTW, this is not really "global", as the manual says. It
really is "outer scope".


julia> macro finish()
 :(t = 5)
   end
julia> macroexpand(:(@finish()))
:(#8#t = 5)

as expected as well.

But:
julia> macro finish()
 :(bar(t))
   end
julia> macroexpand(:(@finish()))
:(bar(t))

unexpected. t is used as a function argument name, so shouldn't it be
considered local and hence gensym'ed ?

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

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


Re: [julia-users] Re: macros design

2016-04-20 Thread Didier Verna
Milan Bouchet-Valat  wrote:

> OTOH, short-circuit operators are in limited number (&& and ||).
> Packages authors cannot create new ones without the user knowing

  Do you mean it's possible to create new short-circuit operators ?

> Yes. For example, DataFrames.jl and DataFramesMeta.jl provide
> functions like where(), by() and aggregate() both in function and
> macro forms.  The former takes a function, while the latter offers a
> convenience syntax which creates a function under the hood.
>
> See in particular this section:
> https://github.com/JuliaStats/DataFramesMeta.jl#operations-on-groupeddataframes

  Thanks.


> I don't think that's possible, as the short-circuit behavior of &&
> means it does not evaluate its second operand if the first one is
> false. So it cannot be a standard function.

  Sure. It would have to be built-in.

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

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


Re: [julia-users] Re: macros design

2016-04-20 Thread Didier Verna
Isaiah Norton  wrote:

> Just to follow up on this a bit: we've continually reworked the
> metaprogramming documentation because it can be an especially
> difficult concept for people who don't have a compiler background or
> Lisp experience. The most common sources of misunderstanding have been
> rooted in people not internalizing that macros, from a definition
> standpoint, are just functions that return expressions. A lot of
> questions on the mailing list treated macros as "spooky magic" (I'll
> admit to feeling this way for a long time!). We want to make them less
> so. Showing explicit returns, and emphasizing macros as
> transformations first, was an attempt to reduce the level of implicit
> knowledge required to understand what is happening.

  Makes sense. Thanks. But now that you've had the opposite reaction,
  perhaps you could add a note that the return is actually not
  needed. :-D

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

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


Re: [julia-users] Re: modules (documentation)

2016-04-20 Thread Didier Verna
Kristoffer Carlsson  wrote:

> Does the following examples help?

  I get it now, I think. Import also loads a module from somewhere if
  it's not present in the environment.

Thanks.

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

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


Re: [julia-users] Re: macros design

2016-04-20 Thread Didier Verna
cormull...@mac.com wrote:

> https://github.com/JuliaLang/julia/blob/3c354b4a391307d84915445bdd6fb464371f30fc/doc/at_macro_reasons
>

Nice, thanks :-)

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

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


[julia-users] Creating symbols

2016-04-20 Thread Didier Verna

  Out of curiosity, why the symbol function? I mean, why not making
  this functionality part of the Symbol constructor?

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

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


[julia-users] modules (documentation)

2016-04-20 Thread Didier Verna

  There are a couple of things that I find obscure in the modules
  documentation.

It says that import operates on a single name at a time, but there's a
counter-example in the table right below this sentence: import MyModule
which looks like it imports a module as a whole.

On the other hand, the table in question says that with such a
directive, MyModule.x (and y and p) are "brought into scope" and
"available for method extension". But from what I could gather, it seems
to me that the dot notation always makes everything available. So it
would rather seem that import MyModule is a no-op. Is that correct?

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

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


[julia-users] Re: macros design

2016-04-20 Thread Didier Verna
I wrote:

>   What's the rationale behind this particular way of invoking macros
>   (the @ character) ? And why a single macro concept for two different
>   things (with or without arguments) ?

Also, I'm wondering about the use of RETURN in all the one-liner
macro examples from the manual. Why not just:

macro sayhello()
  :( println("Hello, world!") )
end

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

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


Re: [julia-users] outer-only constructors

2016-04-19 Thread Didier Verna
Milan Bouchet-Valat  wrote:

> This is an inner constructor, not an outer one. But you would usually
> write it in a very different way. What you did is equivalent to the
> much simpler:
>
> Where did you get this convoluted idea?

  Precisely in the section of the manual you're pointing me too ;-):
  
> This is all documented in the manual:
> http://docs.julialang.org/en/stable/manual/constructors/

  What I did is what's documented in there. This part of the manual is
  very confusing.

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

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


[julia-users] outer-only constructors

2016-04-19 Thread Didier Verna

There's something I don't understand about them:

type Foo
 val
 double
 function call(::Type{Foo}, val)
   new(val, 2*val)
 end
end


I understand here that the programmer explicitly provides a way to call
Foo(3), but how does this prevent calls to Foo(3, 4) from being
automatically defined as usual?

Does the language detect, in some way, the explicit specialization and
stops doing it altogether?

Thanks.

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

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


[julia-users] Re: optional arguments and specializations

2016-04-18 Thread Didier Verna
I wrote:

>   The manual seems wrong about this (0.4.5):
>
> f(a=1,b=2) = a+2b
> f(a::Int,b::Int) = a-2b
> f() # -> 5
> f(1,2) # -> -3
>
> The manual says that both calls give -3. So who's wrong, the language or
> the manual ?

  So it seems that optional arguments /values/ are tied to the methods:

julia> f(a=1,b=2) = a + b
f (generic function with 3 methods)

julia> f(a::Int=3,b::Int=4) = a - b
f (generic function with 5 methods)


julia> f()
-1

julia> f(1.5)
3.5


i.e., there's some memory of different optional values for different
methods.


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

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


Re: [julia-users] Square matrices as a parametric type ?

2016-04-18 Thread Didier Verna
Tim Holy  wrote:

> Since it's open-source you can check on your own :-). But the short
> answer is:

  Yes, but I'm asking here for performance reasons ;-)

Thanks.

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

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


[julia-users] optional arguments and specializations

2016-04-18 Thread Didier Verna

  The manual seems wrong about this (0.4.5):

f(a=1,b=2) = a+2b
f(a::Int,b::Int) = a-2b
f() # -> 5
f(1,2) # -> -3

The manual says that both calls give -3. So who's wrong, the language or
the manual ?

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

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


Re: [julia-users] Square matrices as a parametric type ?

2016-04-18 Thread Didier Verna
Tim Holy  wrote:

> https://github.com/SimonDanisch/FixedSizeArrays.jl and 
> https://github.com/eschnett/FlexibleArrays.jl

  Thanks. What I'm actually interested in is how deep in the language
  this needs to be grounded, since I guess this is not based on the
  AbstractArray interface. Does it need to access the language's
  internals ? How's the underlying storage  done and is it as efficient
  as Julia's native arrays ?

Thank you.

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

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


[julia-users] methods ambiguity

2016-04-18 Thread Didier Verna

  Julia warns you when there's an ambiguity in method specificity, and
  picks one "arbitrarily" (according to the manual). I guess arbitrarily
  doesn't mean random. Is there a particular reason for not
  standardizing a tie-breaker (possibly the one currently in use) ?

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

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


[julia-users] Square matrices as a parametric type ?

2016-04-18 Thread Didier Verna

  Hello,

is there a way to define such a beast? I would like for instance to
express something like this: SquareMatrix{Int32,3} and get instances
that would be similar to 3x3 Array{Int32,2}.

Right now, it seems to me that the available array abstractions only let
you express the rank as part of the type, not the actual dimensions.

Thanks.

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

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


[julia-users] parametric composite types constructors

2016-04-17 Thread Didier Verna

Can someone explain this sentence that I don't understand in the user
manual (parametric composite types section):

"Only one default constructor is generated for parametric types, since
overriding it is not possible."

Thanks.

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

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


Re: [julia-users] scoping wat

2016-04-13 Thread Didier Verna
I wrote:

> Consider for example embedding a for loop in a macro, and the risk for
> variable capture.

  Forget that. Macros seem to be hygienic.

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

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


Re: [julia-users] scoping wat

2016-04-13 Thread Didier Verna
Jeff Bezanson  wrote:

> Yes, one could argue that a `for` loop variable should always be a new
> variable, but that does make the constructs less orthogonal.

  It's funny that you see this as less orthogonal, considering that, as
  Stefan pointed out, your "for" index will leak its final
  value. Consider for example embedding a for loop in a macro, and the
  risk for variable capture. Sounds pretty anti-orthogonal to me...


> In any case I don't see how this is "do or don't, it depends". Depends
> on what?

  Is the i in for(i=1:3) local to the loop? It depends (on whether there
  is an outer i or not).

  Does assignment create a binding? It depends (on the construct you're
  in). E.g.
  julia> if true; k = 10 end # -> 10
  julia> k # -> 10
  julia> let; l = 10 end # -> 10
  julia> l # -> ERROR: UndefVarError: l not defined

  Does assignment in a function create a local binding? It depends (on
  whether the function is nested).

  etc.

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

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


Re: [julia-users] scoping wat

2016-04-13 Thread Didier Verna
Jeff Bezanson  wrote:

> It works this way because we didn't want to require all variables to
> be explicitly introduced with a construct like `var x = 0`. This adds
> a lot of noise to a program and is annoying to those used to python or
> matlab.

  I see your point and I understand the concern for Python or Matlab
  users. You see local declarations as noise whereas as I see it as
  explicit intent. I still have a hard time digesting the fact that
  assignment creates new local bindings, but not always though ;-)

-- 
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 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 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] scoping wat

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

> Your let is broken, it's a no-op. let always creates local bindings

  :-D I know, it was just for the sake of the example. The let was just
  to introduce a block,  I couldn't do that with begin since begin
  doesn't introduce a block!

> I agree that the hard/soft scoping rules are messy. In practice, it
> doesn't seem to cause a lot of issues

  Granted (although this doesn't really justify doing a mess in the
  first place; the same argument applies to Emacs Lisp's dynamic scoping
  by default for instance).

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

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


Re: [julia-users] Re: scoping wat

2016-04-12 Thread Didier Verna
FANG Colin  wrote:

> I think the complicated scoping rules are inevitable in Julia as it is
> a dynamic language.

  This is wrong. Dynamic is not more complicated (look at Lisp, the
  rules are very simple). The complication comes from the rules varying
  depending on the operators (for reasons that look like DWIM to me),
  and again, the mixing of binding and assignment.

> Functional languages have even simpler rules.

  Julia is functional. You must mean purely functional ;-)

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

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


Re: [julia-users] Creating new globals

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

> I don't think the point of global is to create a global variable, but
> moreso to update one.

  Yes, that what's I thought.

> I use global in dlet to implement special variables:

  Nice attempt at dynamic scope ! :-)

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

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


Re: [julia-users] scoping wat

2016-04-12 Thread Didier Verna
Mauro  wrote:

> Maybe you can be a bit more explicit in what you mean, examples would
> help too.

  Sorry for the fuzziness. This is an example of what I mean:

let
  x = 10
end

here, the same expression "x = 10" will either assign a new value to x
if such a /global/ exists, or create a new /local/ binding. This is
already bad enough[1]. Then, begin/end behaves differently. Then, "if"
doesn't introduce a new block, but some others constructs do, and some
don't. And then, some like "for" do or don't, it depends.

Now even worse:
x = 10
function foo()
  println(x)
  x = 5
  println(x)
end

will break on the first println (one could expect to get 10, the global
value for x) because since there is an assignment /later on/, a new
/local/ binding will be created for x (which BTW is the exact opposite
of what let does!), but this binding isn't available to the first
println. And also, since a variable cannot switch from global to local
(or vice-versa) in the same block, the intuition (well, mine anyway ;-))
that after the assignment, the scoping changes, is wrong.

And then, as you mention, nested functions will behave yet
differently. All of this looks really bad.

So IMHO, the real problem is that there are two distinct concepts:
assigning a new value to an existing binding, and creating a new
binding, possibly with an initial assignment. These are separate things
and mixing the two in such ways is wrong, and also quite surprising,
knowing the lispy side of this language.



Footnotes: 
[1]  consider that a simple typo in your code may lead to silently
creating a new variable, which will never be used.

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

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


Re: [julia-users] Creating new globals

2016-04-12 Thread Didier Verna
Mauro  wrote:

> If I understand correctly, you argue that all global bindings should
> be declared in the (lexical) global scope.  An inner scope could then
> use that binding by using `global`.  But new global bindings could not
> be created in local scopes.  I think that would functionally be
> equivalent to the current status.  I have no feeling about which would
> be superior syntactically.

  Right. It's the implicit creation of new bindings that I dislike. Or
  rather, the fact that sometimes new bindings are created, sometimes
  not, depending on the context.

>> 2. also, technically, your lexical closure isn't required for the
>> function itself, but for the particular method you're defining. But I
>> guess there's no way of declaring an empty generic function?
>
> function foo end

  Oh! So, it's exactly that. Your previous example:

let tunnel_port = 9201
global next_tunnel_port
function next_tunnel_port()
# ...
end
end

can actually also be written like this:

function next_tunnel_port end
let tunnel_port = 9201
function next_tunnel_port()
# ...
end
end


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

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


Re: [julia-users] Creating new globals

2016-04-12 Thread Didier Verna
Mauro <mauro...@runbox.com> wrote:

> On Tue, 2016-04-12 at 11:10, Didier Verna <did...@didierverna.net> wrote:
>>   Hello,
>>
>> I'm wondering if anyone has ever seen an actual use for dynamically
>> creating a new global variable by using the "global" keyword from
>> within a local scope?
>
> https://github.com/JuliaLang/julia/blob/6b5a05eb1a029aef93f77b60bb1d745c7d6e1d8d/base/managers.jl#L175

  Thanks, but :-). Two comments (related):

1. in that particular case, you're doing it not really because you want
   to dynamically define your global function, but because you need the
   lexical closure (your let is at the top-level). How about
   non-functional variables?

2. also, technically, your lexical closure isn't required for the
   function itself, but for the particular method you're defining. But I
   guess there's no way of declaring an empty generic function?

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

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


Re: [julia-users] Modules and r/o

2016-04-12 Thread Didier Verna
Mauro <mauro...@runbox.com> wrote:

> On Tue, 2016-04-12 at 11:03, Didier Verna <did...@didierverna.net> wrote:
>> What is the rationale behind module state being read-only from the outside?
>
> Encapsulation?  Seems good to me.

  Hmmm. Not convinced. There are different facets to
  encapsulation. Information hiding seems more important to me, and this
  is orthogonal to mutation. Read: I don't like people to see my private
  parts, even if they don't touch them :-D
  Can you hide information in a module? It seems that even unexported
  variables can be accessed through dot notation.

  In the same vein, I find the behavior of "global" (depending on
  reference vs. assignment) really weird (but there, I could understand
  some concerns for performance in the context of mutation).
  

> Use a function

  Accessors, yeah.


> You can also eval into a module:

  Interesting thanks. Is there such a thing as a mutable "current
  module"? I mean, can you interactively or programmatically switch to
  another module ?


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

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


[julia-users] const functions

2016-04-12 Thread Didier Verna

  What's the rationale behind making "function" const? Is there a
  performance reason?

you can't do

function foo() 0 end
foo = 10

but you can still change the function's definition (so it's methods;
even if the generic remains the same object I guess), and besides, you
can however do this:

bar = () -> 0
bar = 10

Oh, maybe the fact that foo is a generic function but bar an anonymous
one matters?

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

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


[julia-users] Nested global functions

2016-04-12 Thread Didier Verna

  Hello,

I would have expected that this would work (but this is a syntax error):
let
  global function f(x) 2x end
end

This is ok however:
let
  global f = x -> 2x
end

Why isn't the first form allowed?


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


[julia-users] scoping wat

2016-04-12 Thread Didier Verna

  Hi,

I'm quite puzzled by the complication of Julia's scoping rules, and in
particular this way of constantly and implicitly mixing binding and
assignment, with varying semantics according to the context.

The manual is not convincing (at least to me) in justifying what's
happening. Most of the scoping behavior looks like a big DWIM machinery
which is evil.

What's the history behind all this? Technical debt? Inspiration from
other languages (certainly not Scheme!)? Actual, arbitrary design
decisions?

Thank you!

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

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


[julia-users] Creating new globals

2016-04-12 Thread Didier Verna

  Hello,

I'm wondering if anyone has ever seen an actual use for dynamically
creating a new global variable by using the "global" keyword from within
a local scope?

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

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


[julia-users] local vs. let

2016-04-12 Thread Didier Verna

  It seems to me that forcing a variable to be local with the "local"
  keyword is just like creating a new binding for it using "let". So why
  both?

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

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


[julia-users] Modules and r/o

2016-04-12 Thread Didier Verna

What is the rationale behind module state being read-only from the outside?
Is this only be default (i.e., is there a construct to still allow writing)?

Thanks.

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

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


Re: [julia-users] The manual about explicit types

2016-04-06 Thread Didier Verna
Mauro  wrote:

> A pull request is most welcome ;-).  Easiest is if you go to:
> https://github.com/JuliaLang/julia/blob/master/doc/manual/functions.rst
> and click on the little pencil.

  Will do. I also have spotted several other places that would need
  fixing.

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

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


Re: [julia-users] Weird singleton varags display

2016-04-06 Thread Didier Verna
Milan Bouchet-Valat  wrote:

> The first syntax returns an integer: only the second one returns a
> tuple. Parentheses alone only group terms, they don't create a tuple.

  Doh!  That's what I was missing. Thanks!

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

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


Re: [julia-users] Weird singleton varags display

2016-04-06 Thread Didier Verna
Mauro  wrote:

> Did you find:
> http://docs.julialang.org/en/release-0.4/manual/functions/#varargs-functions

  That's while reading this that the question occurred to me.

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

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


[julia-users] The manual about explicit types

2016-04-06 Thread Didier Verna

  I think the section on functions in the user manual should be fixed in
  two places:

- it says "The types of keyword arguments can be made explicit as
  follows" which is misleading because, IIUC, every function parameter
  can have an explicit type.

- in the end, it says "None of the examples given here provide any type
  annotations on their arguments" which is wrong.

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

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


Re: [julia-users] Weird singleton varags display

2016-04-06 Thread Didier Verna
Mauro  wrote:

> It's a tuple.
>
> foo(1,2)
> (1,2)

and foo(1,2,3) => (1,2,3) and so on. But I still don't understand :-)

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

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


[julia-users] Weird singleton varags display

2016-04-06 Thread Didier Verna

  Can somebody please explain this to me:

julia> foo(args...) = args
foo (generic function with 1 method)

foo(1)
(1,)

i.e., why the trailing comma ?

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

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


Re: [julia-users] deprecated syntax foo(): to warn or not to warn ?

2016-04-06 Thread Didier Verna
Isaiah Norton  wrote:

> For explanation, see https://github.com/JuliaLang/julia/issues/7232
> (tl;dr: better support for macro calls *without* parentheses)

  Ouch! So it seems Julia is missing Lisp's distinction between macros
  and symbol-macros. Thanks for the pointer.

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

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


[julia-users] function definitions short form

2016-04-06 Thread Didier Verna

  Just a thought, not important but only for the record.

The long forms for function definition are nicely homogeneous:

function foo(x)
  2x
end

and

function (x)
  2x
end


It's a shame that the short ones aren't. I understand that using
(x) = 2x
for anonymous functions could entail a syntactic collision with
multiple assignment / pattern matching / whateveryoucallit, so perhaps
defining short named function had better be done like this:

foo(x) -> 2x

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

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


[julia-users] deprecated syntax foo(): to warn or not to warn ?

2016-04-06 Thread Didier Verna

  Hello,

1. can somebody please explain why the "foo ()" syntax is deprecated ?

2. also, the warnings policy seems inconsistent to me, or I'm missing
something:

julia> foo (3)
WARNING: deprecated syntax "foo (".
Use "foo(" instead.

julia> (+) (1, 2, 3)
WARNING: deprecated syntax "+ (".
Use "+(" instead.

OK, but then calling "+ (1, 2, 3)" does not issue a warning.

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

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


[julia-users] elementwise operators

2016-04-05 Thread Didier Verna

  I understand that some operators have elementwise versions, when
  prefixed with a dot. I think the manual is missing some dots, like in
  this paragraph, right ?

"The operator < is intended for array objects; the operation A .< B is
valid only if A and B have the same dimensions. The operator returns an
array with boolean entries and with the same dimensions as A and B. Such
operators are called elementwise; Julia offers a suite of elementwise
operators: *, +, etc."

  Also, is there a true mechanism for elementwise'ing operators ? Or are
  those just a collection of built-ins following the same naming
  convention ?

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] litteral floats

2016-04-05 Thread Didier Verna
Isaiah Norton  wrote:

> Yes. (x86 has had double support for a long time and so do most
> high-end ARM chips)

  Thank you.

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] overflow behavior

2016-04-05 Thread Didier Verna
Erik Schnetter  wrote:

> The literal `1` has type `Int`.  The promotion rules for `Int8` and
> `Int` state that, before the addition, `Int8` is converted to `Int`.
> (On your system, it seems that `Int` is `Int64`.)

  OK, so indeed, there's modular arithmetics for the non native
  representations as well. It's just that litterals are neither
  overloaded, nor implicitly transtyped. I see, thanks.

-- 
Resistance is futile. You will be jazzimilated.

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


Re: [julia-users] Re: overflow behavior

2016-04-05 Thread Didier Verna
Páll Haraldsson  wrote:

> Right, the manual could be updated, I guess. The last one, gives you
> Int32 on 32-bit platforms.

  I expected as much, indeed.

-- 
Resistance is futile. You will be jazzimilated.

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


[julia-users] litteral floats

2016-04-05 Thread Didier Verna

The manual says: "The above results [e.g. 1.5e0] are all Float64
values. Literal Float32 values can be entered by writing an f in place
of e".

But is that also the case on 32bits systems ?

-- 
Resistance is futile. You will be jazzimilated.

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


[julia-users] overflow behavior

2016-04-05 Thread Didier Verna

  Hello,

the manual says: "In Julia, exceeding the maximum representable value of
a given type results in a wraparound behavior:", but that seems to be
the case only for the native type and above:

julia> typeof(typemax(Int64)  + 1) -> Int64
julia> typeof(typemax(Int128) + 1) -> Int128

but:

julia> typeof(typemax(Int8)   + 1) -> Int64
julia> typeof(typemax(Int16)  + 1) -> Int64
julia> typeof(typemax(Int32)  + 1) -> Int64

These last 3 results seem inconsistent (and the manual incorrect)
because for example, typeof(typemax(Int8)) -> Int8 and not Int64, so no,
Julia doesn't do modular arithmetics all the time.

-- 
Resistance is futile. You will be jazzimilated.

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


[julia-users] prefix / infix syntax bridge

2016-04-05 Thread Didier Verna

  Hi,

the user manual says this (VARIABLES section):

"Operators like + are also valid identifiers, but are parsed
specially. In some contexts, operators can be used just like variables;
for example (+) refers to the addition function, and (+) = f will
reassign it."

This looks like Haskell's bridge between the infix and prefix
syntax. However, it seems that contrary to what the manual says, you
don't need the parenthesis, i.e. I can do just x = f. So is there a real
reason for using (+) ?

Also another question: is it possible, as in Haskell, to define new
infix operators, or are you restricted[1] to the built-in ones ?

Thanks.


Footnotes: 
[1]  by "restricted" here, I don't mean to say that there are too few of
them; I'm aware the unicode ones are available.

-- 
Resistance is futile. You will be jazzimilated.

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


[julia-users] double-dash cmdline syntax doesn't work ?

2016-03-30 Thread Didier Verna

  Hello,

I've installed Julia 0.4.5 on my Mac and I'm reading the user manual...

The Getting Started section mentions the double-dash cmdline syntax, but
it doesn't seem to work. With the script given as example that just
shows the value of ARGS, I get this:

didier(s000)% julia --color=yes -- /tmp/test.jl foo bar
ERROR: could not open file /Users/didier/--
[...]

However, it works without the double-dash:
didier(s000)% julia --color=yes /tmp/test.jl foo bar
foo
bar

This behavior seems in contradiction with Julia's synopsis:
didier(s000)% julia --help
julia [switches] -- [programfile] [args...]


Thanks.

-- 
Resistance is futile. You will be jazzimilated.

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