[julia-users] Calling Fortran code?

2016-06-05 Thread Charles Ll
Dear all,

I am trying to call some Fortran code in Julia, but I have a hard time 
doing so... I have read the docs, looked at the wrapping of ARPACK and 
other libraries... But I did not find any way to make it work.

I am trying to wrap a spline function library 
(gcvspl.f, https://github.com/charlesll/Spectra.jl/tree/master/Dependencies), 
which I want to use in my project, Spectra.jl.

I already have a wrapper in Python, but this was easier to wrap with using 
f2py. In Julia, I understand that I have to do it properly. The function I 
am trying to call is:
GCVSPL ( X, Y, NY, WX, WY, M, N, K, MD, VAL, C, NC, WK, IER) (LINE 42 of 
GCVSPL.f)


X(N)( I )   Independent variables, Float64
Y(NY,K)   ( I )   Input data to be smoothed (or interpolated), Float64
NY   ( I )   First dimension of array Y(NY,K), with NY.ge.N, 
Integer
WX(N) ( I )   Weight factor array, Float64
WY(K) ( I )   Weight factor array, Float64
M ( I )   M = 1,2,3,4 correspond to linear, cubic, quintic, 
and heptic splines, respectively. Integer
N ( I )   Number of observations per dataset, Integer
K( I )   Number of datasets, with K.ge.1., Integer
MD ( I )   Optimization mode switch, Integer
VAL( I )   Mode value, as described above under MD., Array of 
Float64
C(NC,K)( O )   Spline coefficients, Array of Float64
NC ( I )  First dimension of array C(NC,K), NC.ge.N., Integer
WK(IWK) (I/W/O) Work vector, IWK.ge.6*(N*M+1)+N, Array of Float64
IER( O )   Error parameter, Integer

with I and O designating Inputs and Outputs, respectively. From this and my 
previous Python wrap, I generated a fake dataset and tried to use this 
function with ccall:

x = collect(0.0:1.0:100)
y = 2.0.*x.^2 - 100.0 + x +0.0003.*x.^5
ese = y./1


NN::Int64 = length(y)
wx = 1./(ese.^2) # relative variance of observations
wy = zeros([1])+1 # systematic errors... not used so put them to 1, works 
under the Python wrap
VAL = ese.^2


M::Int64 = 2
N::Int64 = length(x)
K::Int64 = 1 # number of y columns
MD::Int64 = 2 #spline mode
NC::Int64 = length(y)

# initialising stuffs for outputs... isit the right way?
c = ones(NN,NC)
WK = [1.,1.,1.,1.,1.,1.]
IER::Int64 = 0


ccall( (:gcvspl_, "./libgcvspl.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{
Int64},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Int64},Ptr{Int64},Ptr{Int64
},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Float64},Ptr{Int64}),x,y,NN,wx,wy
,M,N,K,MD,VAL,c,NN,WK,IER)

This code does not work, returning me some convert problems... Notably, I 
get this one:

LoadError: MethodError: `convert` has no method matching 
convert(::Type{Ptr{Float64}}, ::Array{Int64,1})


That I don't understand... In the "examples" (code already wrapped...) 
available online, that was the way people wrapped stuffs... 

Do anyone has some clue about doing this wrapping? The gcvspl.f code is 
available 
in https://github.com/charlesll/Spectra.jl/tree/master/Dependencies .

Thanks in advance!

Best,
Charles.




[julia-users] Re: readdlm throws error for empty line

2016-06-05 Thread Tanmay K. Mohapatra
I see the message: "file entry \"\" cannot be converted to Float64"
This is because you are trying to read it as a Float64 matrix and there are 
missing values in the input that can not be represented with Float64.

If I don't specify the type, I get:

julia> readdlm("/tmp/x.csv", ',')
2×3 Array{Any,2}:
 1  2   ""
 5  2  4  

Empty lines are ignored.

On Monday, June 6, 2016 at 3:46:18 AM UTC+5:30, Anonymous wrote:
>
> So I have a BysteString vector A, containing a bunch of byte strings of 
> varying lengths of the form:
>
> "1,2,\n"
> "\n"
> "5,2,4\n"
>
> etc. 
>
> What I have set up is to do 
>
> [vec(readdlm(IOBuffer(line), ',', Float64)) for line in A]
>
> However because as you see above the second line is empty except for the 
> newline escape character, it throws an error.  What I would like it to do 
> instead is simply return an empty array Float64[] for that line.  That 
> seems like what it *should* do, and I'm not sure why it doesn't.  Is 
> there any way I can make it behave like I want it to?
>


Re: [julia-users] readdlm throws error for empty line

2016-06-05 Thread Anonymous
it does appear to be related, unfortunately no resolution appears to be as 
of yet forth coming.

On Sunday, June 5, 2016 at 6:53:56 PM UTC-7, Miguel Bazdresch wrote:
>
> This may be related: https://github.com/JuliaLang/julia/issues/16248
>
> On Sun, Jun 5, 2016 at 6:16 PM, Anonymous  
> wrote:
>
>> So I have a BysteString vector A, containing a bunch of byte strings of 
>> varying lengths of the form:
>>
>> "1,2,\n"
>> "\n"
>> "5,2,4\n"
>>
>> etc. 
>>
>> What I have set up is to do 
>>
>> [vec(readdlm(IOBuffer(line), ',', Float64)) for line in A]
>>
>> However because as you see above the second line is empty except for the 
>> newline escape character, it throws an error.  What I would like it to do 
>> instead is simply return an empty array Float64[] for that line.  That 
>> seems like what it *should* do, and I'm not sure why it doesn't.  Is 
>> there any way I can make it behave like I want it to?
>>
>
>

Re: [julia-users] readdlm throws error for empty line

2016-06-05 Thread Miguel Bazdresch
This may be related: https://github.com/JuliaLang/julia/issues/16248

On Sun, Jun 5, 2016 at 6:16 PM, Anonymous  wrote:

> So I have a BysteString vector A, containing a bunch of byte strings of
> varying lengths of the form:
>
> "1,2,\n"
> "\n"
> "5,2,4\n"
>
> etc.
>
> What I have set up is to do
>
> [vec(readdlm(IOBuffer(line), ',', Float64)) for line in A]
>
> However because as you see above the second line is empty except for the
> newline escape character, it throws an error.  What I would like it to do
> instead is simply return an empty array Float64[] for that line.  That
> seems like what it *should* do, and I'm not sure why it doesn't.  Is
> there any way I can make it behave like I want it to?
>


Re: [julia-users] errors using packages in parallel

2016-06-05 Thread Ethan Anderes
I just submitted an issue:  github.com/JuliaLang/julia/issues/16778
>
>
Thanks for everyones input.

Ethan


[julia-users] Re: A question about expressions

2016-06-05 Thread Cedric St-Jean
Technically, it's because k is not assigned to anything. Your for loop is 
quoted, which means that it's just an expression, not an actual for loop. 
The dollar-sign tells Julia to stop quoting and insert the result of the 
expression `vars[k]`, but k isn't defined, so you get an error. Compare:

:(10 + x)# no error
:(10 + $x)  # error: x isn't defined

If this isn't clear, I would suggest reading some tutorial on macros.

On Sunday, June 5, 2016 at 8:41:58 PM UTC-4, Richard Dennis wrote:
>
> I'm fiddling around with expressions and I'm puzzled why the following 
> tells me that k is not defined.  Any thoughts would be appreciated.
>
> # a = is a 3D array
> # b = a vector of vectors
>
> vars = [[symbol("i1")]; [symbol("i2")]; [symbol("i3")]]
> glomp = :( inner_prod = a[$(vars...)];
>  for k = 1:size(b,1);
>   inner_prod *= b[k][$(vars[k])];
>  end;
>  )
>
> I realize that it is probably obvious, but the reason eludes me.
>


[julia-users] A question about expressions

2016-06-05 Thread Richard Dennis
I'm fiddling around with expressions and I'm puzzled why the following 
tells me that k is not defined.  Any thoughts would be appreciated.

# a = is a 3D array
# b = a vector of vectors

vars = [[symbol("i1")]; [symbol("i2")]; [symbol("i3")]]
glomp = :( inner_prod = a[$(vars...)];
 for k = 1:size(b,1);
  inner_prod *= b[k][$(vars[k])];
 end;
 )

I realize that it is probably obvious, but the reason eludes me.


[julia-users] Reconstruct a string from a Clang.jl generated looong type

2016-06-05 Thread J Luis
Hi,

I have one of those types generated from a C struct with Clang.jl that 
turns a stack variable into a lng list of members (for example (but I 
have longer ones))

https://github.com/joa-quim/GMT.jl/blob/master/src/libgmt_h.jl#L1246

(an in interlude: isn't yet any better way of representing a C "char 
str[256];"?)

when executed I get (example)

julia> hdr.x_units
GMT.Array_80_Uint8(0x6c,0x6f,0x6e,0x67,0x69,0x74,0x75,0x64,0x65,0x20,0x5b,
0x64,0x65,0x67,0x72,0x65,0x65,0x73,0x5f,0x65,0x61,0x73,0x74,0x5d,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00)

but I need to transform it into a string. After some suffering I came out 
with this solution

julia> join([Char(hdr.x_units.(n)) for n=1:sizeof(hdr.x_units)])
"longitude 
[degrees_east]\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

well, it works but it's kind or ugly. Is there a better way of achieving 
this? Namely, how could I avoid creating a string with all of those \0's? I 
know I can remove them after, but what about not copying them on first 
place?

Thanks



[julia-users] readdlm throws error for empty line

2016-06-05 Thread Anonymous
So I have a BysteString vector A, containing a bunch of byte strings of 
varying lengths of the form:

"1,2,\n"
"\n"
"5,2,4\n"

etc. 

What I have set up is to do 

[vec(readdlm(IOBuffer(line), ',', Float64)) for line in A]

However because as you see above the second line is empty except for the 
newline escape character, it throws an error.  What I would like it to do 
instead is simply return an empty array Float64[] for that line.  That 
seems like what it *should* do, and I'm not sure why it doesn't.  Is there 
any way I can make it behave like I want it to?


[julia-users] Problem with Homebrew after Pkg.update()

2016-06-05 Thread Tony Kelman
Which version of Homebrew.jl did you update to? What does Pkg.status() say?


Re: [julia-users] How to build a range of -Inf to Inf

2016-06-05 Thread Páll Haraldsson
On Friday, June 3, 2016 at 2:54:57 AM UTC, Yichao Yu wrote:
>
> A Range is not a interval


Right.
 

> but rather a series of equally spaced numbers

 
Actually, they do not have to be equally spaced (for the straightforward 
definition)? Not the abstract Range, while "equally spaced" seems to fit 
the lower case range-function.

You are thinking of e.g. StepRange, the concrete type you are likely to get.

I do second e.g. the Unum suggestion (that is implemented, and has -Inf and 
+Inf) and Unum version 2.0 (that isn't implemented yet [in Julia], that I 
know of; only has +-Inf) might have few enough bit-patterns that you could 
usefully have a Range that steps through them all.

I'm not sure this is a helpful comment, that you would want go through 
every bit-pattern (or every Nth); I'm kind of asking. Unums are just very 
interesting to me, as an abstraction of the whole real-line (and better 
match for it). [Look into SCORNs to have no gaps on the real-line of Unums 
2.0.]

[At least nzrange, goes though unspaced numbers, while the indexes to them 
are "spaced".]


help?> Range
search: Range range RangeIndex nzrange linrange UnitRange StepRange 
histrange FloatRange ClusterManager trailing_zeros trailing_ones 
OrdinalRange
[..]

[Why is e.g. ClusterManager and trailing_zeros displayed? I can see why 
RangeIndex is listed, based on the name, but actually it's a Union, not a 
Range.]

so a range with `Inf` as start/end is basically meaningless. 
> You should probably find another datastructure. 
>
> > 
> > Cheers, 
> > 
> > Colin 
> > 
> > 
>
>

[julia-users] Problem with Homebrew after Pkg.update()

2016-06-05 Thread Fabrice Collard
Hello,

I ran a Pkg.update() this morning, and got Homebrew updated. However, it 
did not properly build, I got the following error message

*INFO: Building Homebrew*

HEAD is now at dde20cd Remove (almost) everything (#50678)

Updating tap homebrew-juliadeps

HEAD is now at c377b50 Merge pull request #92 from staticfloat/staging

Error: Unknown command: outdated

*==[ ERROR: Homebrew 
]===*


*LoadError: failed process: 
Process(`/Users/fabrice/.julia/v0.4/Homebrew/deps/usr/bin/brew outdated`, 
ProcessExited(1)) [1]*

*while loading /Users/fabrice/.julia/v0.4/Homebrew/deps/build.jl, in 
expression starting on line 2*


**


*==[ BUILD ERRORS 
]==*


*WARNING: Homebrew had build errors.*


* - packages with build errors remain installed in 
/Users/fabrice/.julia/v0.4*

* - build the package(s) and all dependencies with `Pkg.build("Homebrew")`*

* - build a single package by running its `deps/build.jl` script*


**


I tried to run the Pkg.build("Homebrew") but got the same. Since then I 
cannot run julia in jupyter, and the kernel dies systematically. Is there 
anything I can do to fix it?


Thanks in advance




Re: [julia-users] Re: big on the mac with large matrices

2016-06-05 Thread Rodrigo Miranda
Happens on my install as well.

versioninfo() ->

ulia Version 0.4.5

Commit 2ac304d (2016-03-18 00:58 UTC)

Platform Info:

  System: Darwin (x86_64-apple-darwin13.4.0)

  CPU: Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz

  WORD_SIZE: 64

  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)

  LAPACK: libopenblas64_

  LIBM: libopenlibm

  LLVM: libLLVM-3.3


I have the 0.45 binary downloaded from the julia.org site.

Best,

Rodrigo

-- Rodrigo Miranda

"We are just an advanced breed of monkeys on a minor planet of a very
average star. But we can understand the Universe. That makes us something
very special." - Stephen Hawking quoted in Der Spiegel

On Fri, Jun 3, 2016 at 6:54 PM, Stefan Karpinski 
wrote:

> What BLAS library are you using? I.e. what is the output of versioninfo()?
>
> On Fri, Jun 3, 2016 at 5:17 PM, Steven G. Johnson 
> wrote:
>
>>
>>
>> On Friday, June 3, 2016 at 3:16:17 PM UTC-4, Jeremy Kozdon wrote:
>>>
>>> On my mac (and the several other macs I have tried) the following
>>> command in Julia 0.4.5
>>>
>>>eig(rand(3000,3000))
>>>
>>> causes Julia to crash. It seems to run fine on my linux machines and
>>> JuliaBox.
>>
>>
>> Works fine for me on my Mac with both Julia 0.4.3 and 0.4.5
>>
>> julia> @time eig(rand(3000,3000))
>>  69.368845 seconds (668.10 k allocations: 780.731 MB, 0.30% gc time)
>>
>>
>


[julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
Thanks for the replies.

I have been comparing ansi c syntax and julia lately, so I had to naturally 
ask, why julia doesn't define functions in the same way ansi c does?
foo(args...) begin # ansi c style definition
 #some code
end

If julia would define functions like this, a *keyword for one line block* 
(one line begin end) could be introduced, lets say '->' 

You could then
foo(args..) -> args # one liner
 (args) -> args # natural anonymous function
if true -> return x # one line if

These came onto my mind in first 10 secs, maybe there are *more* useful 
cases.

But then I realised that this definition would clash with macros, because 
you would have no more any function keyword.
So you would have to either 
*(1)* make every callable with '@' in name a macro automatically
  - In this case you would have to make a special case for macro definition 
since right now, when compiler sees @foo, he tries to evaluate that. So the 
special rule would have to be something like this
@foo(args...)begin ... end  #macro definition, because block follows
(@foo(args...)begin ... end #not macro definition, because closed in (), 
macro will be evaluated
@foo(args...) -> ...# macro def
(@foo(args...) -> ...   # not macro def ...
*(2) *or make every callable both function or macro
  - That's what I was asking about.

So that was basically my though process. 
I guess my ideas were too simple as always so it would be not possible to 
implement it anyway, even  tho it looks kinda cool ( at least to me ). :)





RE: [julia-users] errors using packages in parallel

2016-06-05 Thread Boylan, Ross
I've been encountering errors with packages in parallel, even though everything 
is happening on one machine (julia -p 4 or -p 3 under ESS).  This isn't 
necessarily the same issue, but it seems suggestive it's arising at the same 
time.

Originally I think the packages/cache were a bit out of date, and when I ran in 
parallel things went wrong and rebuilt everywhere.  If they were all rebuilding 
in the same spot, as they seemed to, it's easy to imagine that would cause 
problems.  I also had a single CPU copy of julia running at the same time 
(idle) throughout.

After that I started up a single cpu version, did a Pkg.update(), and ran my 
code.  Everything seemed OK.

However, I then ran a parallel julia, and continued to get errors.  The 
included code is all in a module and connect to a Postgresql DB to get some 
data.

Here are excerpts from the sessions:

   | | | | | | |/ _' |  |
   | | |_| | | | (_| |  |  Version 0.4.6-pre+28 (2016-04-22 00:59 UTC)
  _/ |\__'_|_|_|\__'_|  |  Commit 022917e (44 days old release-0.4)
 |__/   |  x86_64-linux-gnu

 WARNING: Terminal not fully functional
 julia>
 julia> nprocs()
 5

 julia> now()
 2016-06-05T00:04:52  # Pacific time US
julia> @everywhere include("trouble.jl")
 INFO: Recompiling stale cache file /home/ross/.julia/lib/v0.4/Debug.ji for 
module Debug.
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/PDMats.ji
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/PDMats.ji
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/PDMats.ji
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/PDMats.ji
 WARNING: Module PDMats uuid did not match cache file
   This is likely because module PDMats does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/Distributions.ji
 WARNING: Module PDMats uuid did not match cache file
   This is likely because module PDMats does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/Distributions.ji
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/StatsFuns.ji
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/StatsFuns.ji
 WARNING: Module PDMats uuid did not match cache file
   This is likely because module PDMats does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/Distributions.ji
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/StatsFuns.ji
 WARNING: Module PDMats uuid did not match cache file
   This is likely because module PDMats does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/Distributions.ji
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 
/home/ross/.julia/lib/v0.4/StatsFuns.ji
 WARNING: Module Compat uuid did not match cache file
   This is likely because module Compat does not support  precompilation but is 
imported by a module that does.
 WARNING: deserialization checks failed while attempting to load cache from 

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Yuri Vishnevsky
I might be wrong here, but you could imagine "unifying" macros and 
functions, allowing people to call any function as a macro by prepending a 
@, or calling any macro as a function by omitting it.

I don't know whether this would be useful, but it's how I read Ford's 
question.


On Sunday, June 5, 2016 at 12:36:30 PM UTC-4, Stefan Karpinski wrote:
>
> On Sun, Jun 5, 2016 at 11:41 AM, Scott Jones  > wrote:
>
>> On the other hand, that would prevent having a function with the same 
>> name as a macro.
>
>
> This is the primary reason. When you define a macro named "@foo", the 
> transformation function for it is bound to the non-standard symbol "@foo":
>
> julia> macro foo(x) esc(x) end
> @foo (macro with 1 method)
>
> julia> getfield(Main, Symbol("@foo"))(:(x + y))
> :($(Expr(:escape, :(x + y
>
>
> You can actually define a macro with the function syntax by using eval to 
> splice in a macro-like name for the function:
>
> julia> @eval function $(Symbol("@foo"))(x) esc(x) end
> @foo (macro with 1 method)
>
> julia> macroexpand(:(@foo x + y))
> :(x + y)
>
>
> So the syntax for macro definition could be changed to something like this:
>
> function @foo(x) esc(x) end
>
>
> However this short form:
>
> @foo(x) = esc(x)
>
>
> would not work since it's ambiguous with having a macro call be the left 
> hand side of an assignment.
>


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Stefan Karpinski
On Sun, Jun 5, 2016 at 11:41 AM, Scott Jones 
wrote:

> On the other hand, that would prevent having a function with the same name
> as a macro.


This is the primary reason. When you define a macro named "@foo", the
transformation function for it is bound to the non-standard symbol "@foo":

julia> macro foo(x) esc(x) end
@foo (macro with 1 method)

julia> getfield(Main, Symbol("@foo"))(:(x + y))
:($(Expr(:escape, :(x + y


You can actually define a macro with the function syntax by using eval to
splice in a macro-like name for the function:

julia> @eval function $(Symbol("@foo"))(x) esc(x) end
@foo (macro with 1 method)

julia> macroexpand(:(@foo x + y))
:(x + y)


So the syntax for macro definition could be changed to something like this:

function @foo(x) esc(x) end


However this short form:

@foo(x) = esc(x)


would not work since it's ambiguous with having a macro call be the left
hand side of an assignment.


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Scott Jones
I think it may just boil down to being a historical artifact - until 
recently (and only in v0.5, AFAIK), macros were handled rather differently 
from functions.
Now that macros actually act like functions, and have different methods (of 
course limited to types known at parse time, symbols, numeric literals, 
etc.),
it might be more consistent to simply have macros defined as functions.

I.e. instead of:
macro foo(x)
  return :( $(string("Prefix",x)))
end
you could have
foo(x) = :( $(string("Prefix",x)))

On the other hand, that would prevent having a function with the same name 
as a macro.

On Sunday, June 5, 2016 at 10:48:51 AM UTC-4, Rafael Fourquet wrote:
>
> I think the OP's question is not about the difference between a macro 
> and a function, but rather about the syntactic way of defining a 
> macro: if a macro can be seen as a function taking an expression and 
> returning another one, why can't we just define a macro with the 
> standard function syntax (i.e. without the macro keyword), and inform 
> the compiler that we want to use it as a macro only at the call site, 
> by invoking it prepended with the @ sign. 
>


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Steven G. Johnson
Macro calls are syntactically distinct from function calls in part because they 
are evaluated at parse time, before the compiler can know the bindings of 
variables (which would be necessary in order to determine whether f(x) is a 
function call or a macro call without the @). 

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
Exactly.

On Sunday, June 5, 2016 at 4:48:51 PM UTC+2, Rafael Fourquet wrote:
>
> I think the OP's question is not about the difference between a macro 
> and a function, but rather about the syntactic way of defining a 
> macro: if a macro can be seen as a function taking an expression and 
> returning another one, why can't we just define a macro with the 
> standard function syntax (i.e. without the macro keyword), and inform 
> the compiler that we want to use it as a macro only at the call site, 
> by invoking it prepended with the @ sign. 
>


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Rafael Fourquet
I think the OP's question is not about the difference between a macro
and a function, but rather about the syntactic way of defining a
macro: if a macro can be seen as a function taking an expression and
returning another one, why can't we just define a macro with the
standard function syntax (i.e. without the macro keyword), and inform
the compiler that we want to use it as a macro only at the call site,
by invoking it prepended with the @ sign.


Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Erik Schnetter
In the hope of bringing a derailed conversation back on track:

Ford, maybe you are not asking a Julia but a general computer science
question. In this case: A macro is strictly more powerful than a function,
so in principle, every function can be replaced by a macro. There are
various "technical" details to get right (i.e. scoping, preventing name
clashes) that make this non-trivial.

However, a much stronger argument for functions is current compiler
technology. For example, Julia compiles a whole function at a time, which
makes it impossible to have recursive macros. Also, since Julia can inline
functions, but won't "anti-inline" common expressions, this would lead to
rather bad code. Thus, from a practical point of view, you can use macros
instead of functions only for small functions without sacrificing
efficiency.

In fact, when you write a macro in Julia, you'll often find that you need
to break a large macro into functions, and then substitute calls to these
functions instead of the code you'd like to generate.

-erik



On Sun, Jun 5, 2016 at 9:06 AM, Ford O.  wrote:

> ...
> I think I gave you all help I could, to understand the question. I am not
> going to explain it over and over and over.
>
>
> On Sunday, June 5, 2016 at 2:40:31 PM UTC+2, Tamas Papp wrote:
>>
>> I am sorry --- I did not realize you had anger management issues.  In
>> any case, consider the example in the section of the manual I linked,
>> with macros and functions:
>>
>> macro time_mac(ex)
>>   return quote
>> local t0 = time()
>> local val = $ex
>> local t1 = time()
>> println("elapsed time: ", t1-t0, " seconds")
>> val
>>   end
>> end
>>
>> function time_fun(ex)
>>   return quote
>> local t0 = time()
>> local val = $ex
>> local t1 = time()
>> println("elapsed time: ", t1-t0, " seconds")
>> val
>>   end
>> end
>>
>> Then observe the output of
>>
>> time_fun(:(foo()))
>>
>> macroexpand(:(@time_mac(foo()))
>>
>> On Sun, Jun 05 2016, Ford O. wrote:
>>
>> > Don't make me angry.
>> >
>> > I have read that chapter more than 5 times.
>> > You could also read my question 5 times.
>> >
>> > I am asking why do we have to specify macro and function with different
>> > keyword, when compiler exactly knows whether we are calling macro or
>> > function.
>> >
>> > Example for ...:
>> > callable foo(e::Expr) = :()
>> > @foo 2 + 2
>> > foo(2 + 2)
>> > # two versions of foo callable are compiled, one as macro, one as
>> function
>> >
>> > Does the *macro *keyword have any significance for compiler?
>> >
>> > On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote:
>> >>
>> >> Sorry for linking a local version of the manual -- still, you could
>> >> probably have found it with a bit of effort, but it appears that you
>> are
>> >> adamant in your refusal to read it.
>> >>
>> >> I would say that the most important reasons is that macros have
>> special
>> >> conventions because of hygiene, see
>> >>
>> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene
>> >>
>> >> Some languages (eg Common Lisp) have the same namespace for macros and
>> >> functions, Julia distinguishes them with @. So they are not as
>> seamless
>> >> as in CL, but at the same time they stand out and warn the reader that
>> >> source transformation is going on. There could be arguments for both
>> >> choices, but Julia chose this one.
>> >>
>> >> On Sun, Jun 05 2016, Ford O. wrote:
>> >>
>> >> > You got it wrong.
>> >> > In different words.
>> >> >
>> >> > Why do we need to specify macro and function block with macro and
>> >> function
>> >> > keyword? Isnt the '@' symbol enough?
>> >> >
>> >> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote:
>> >> >>
>> >> >> A macro is a function that is used to transform (a representation)
>> of
>> >> >> source code. Consequently, it is called when Julia evaluates your
>> >> >> function defintions, not at runtime. Please read
>> >> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html
>> where
>> >> >> you find examples.
>> >> >>
>> >> >> Regarding you example: it is unclear what you are trying to do, but
>> >> >> unless you use the macro keyword, you get an ordinary function, not
>> a
>> >> >> macro.
>> >> >>
>> >> >> On Sun, Jun 05 2016, Ford O. wrote:
>> >> >>
>> >> >> > What makes macro different from function?
>> >> >> >
>> >> >> > Why is it not possible to do:
>> >> >> > foo(e::Expr) = :()
>> >> >> > @foo x = x + 5
>> >> >> >
>> >> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote:
>> >> >> >
>> >> >> >  I think this deserves an own topic.
>> >> >> >
>> >> >> >  You should post here syntax that looks like duplicate or you
>> think
>> >> it
>> >> >> could use already existing keyword. (mark with # identical or #
>> >> >> replacement)
>> >> >> >  Rule of thumb - the less special syntax the better.
>> >> >> >
>> >> >> >  # identical
>> >> >> >  # replace ' , ' with ' ; ' in arrays ?
>> >> >> >  [1, 2, 3, 4]

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
...
I think I gave you all help I could, to understand the question. I am not 
going to explain it over and over and over.

On Sunday, June 5, 2016 at 2:40:31 PM UTC+2, Tamas Papp wrote:
>
> I am sorry --- I did not realize you had anger management issues.  In 
> any case, consider the example in the section of the manual I linked, 
> with macros and functions: 
>
> macro time_mac(ex) 
>   return quote 
> local t0 = time() 
> local val = $ex 
> local t1 = time() 
> println("elapsed time: ", t1-t0, " seconds") 
> val 
>   end 
> end 
>
> function time_fun(ex) 
>   return quote 
> local t0 = time() 
> local val = $ex 
> local t1 = time() 
> println("elapsed time: ", t1-t0, " seconds") 
> val 
>   end 
> end 
>
> Then observe the output of 
>
> time_fun(:(foo())) 
>
> macroexpand(:(@time_mac(foo())) 
>
> On Sun, Jun 05 2016, Ford O. wrote: 
>
> > Don't make me angry. 
> > 
> > I have read that chapter more than 5 times. 
> > You could also read my question 5 times. 
> > 
> > I am asking why do we have to specify macro and function with different 
> > keyword, when compiler exactly knows whether we are calling macro or 
> > function. 
> > 
> > Example for ...: 
> > callable foo(e::Expr) = :() 
> > @foo 2 + 2 
> > foo(2 + 2) 
> > # two versions of foo callable are compiled, one as macro, one as 
> function 
> > 
> > Does the *macro *keyword have any significance for compiler? 
> > 
> > On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote: 
> >> 
> >> Sorry for linking a local version of the manual -- still, you could 
> >> probably have found it with a bit of effort, but it appears that you 
> are 
> >> adamant in your refusal to read it. 
> >> 
> >> I would say that the most important reasons is that macros have special 
> >> conventions because of hygiene, see 
> >> 
> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene 
> >> 
> >> Some languages (eg Common Lisp) have the same namespace for macros and 
> >> functions, Julia distinguishes them with @. So they are not as seamless 
> >> as in CL, but at the same time they stand out and warn the reader that 
> >> source transformation is going on. There could be arguments for both 
> >> choices, but Julia chose this one. 
> >> 
> >> On Sun, Jun 05 2016, Ford O. wrote: 
> >> 
> >> > You got it wrong. 
> >> > In different words. 
> >> > 
> >> > Why do we need to specify macro and function block with macro and 
> >> function 
> >> > keyword? Isnt the '@' symbol enough? 
> >> > 
> >> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote: 
> >> >> 
> >> >> A macro is a function that is used to transform (a representation) 
> of 
> >> >> source code. Consequently, it is called when Julia evaluates your 
> >> >> function defintions, not at runtime. Please read 
> >> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html 
> where 
> >> >> you find examples. 
> >> >> 
> >> >> Regarding you example: it is unclear what you are trying to do, but 
> >> >> unless you use the macro keyword, you get an ordinary function, not 
> a 
> >> >> macro. 
> >> >> 
> >> >> On Sun, Jun 05 2016, Ford O. wrote: 
> >> >> 
> >> >> > What makes macro different from function? 
> >> >> > 
> >> >> > Why is it not possible to do: 
> >> >> > foo(e::Expr) = :() 
> >> >> > @foo x = x + 5 
> >> >> > 
> >> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
> >> >> > 
> >> >> >  I think this deserves an own topic. 
> >> >> > 
> >> >> >  You should post here syntax that looks like duplicate or you 
> think 
> >> it 
> >> >> could use already existing keyword. (mark with # identical or # 
> >> >> replacement) 
> >> >> >  Rule of thumb - the less special syntax the better. 
> >> >> > 
> >> >> >  # identical 
> >> >> >  # replace ' , ' with ' ; ' in arrays ? 
> >> >> >  [1, 2, 3, 4] 
> >> >> >  [1; 2; 3; 4] 
> >> >> > 
> >> >> >  # identical 
> >> >> >  # replace ' = ' with ' in ' in for loops ? 
> >> >> >  for i = 1:10 
> >> >> >  for i in 1:10 
> >> >> > 
> >> >> >  # replacement 
> >> >> >  # replace ' -> ' with ' = ' in anonymous functions ? 
> >> >> >  (a, b, c) -> a + b + c 
> >> >> >  (a, b, c) = a + b + c 
> >> >> 
> >> >> 
> >> 
> >> 
>
>

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Tamas Papp
I am sorry --- I did not realize you had anger management issues.  In
any case, consider the example in the section of the manual I linked,
with macros and functions:

macro time_mac(ex)
  return quote
local t0 = time()
local val = $ex
local t1 = time()
println("elapsed time: ", t1-t0, " seconds")
val
  end
end

function time_fun(ex)
  return quote
local t0 = time()
local val = $ex
local t1 = time()
println("elapsed time: ", t1-t0, " seconds")
val
  end
end

Then observe the output of

time_fun(:(foo()))

macroexpand(:(@time_mac(foo()))

On Sun, Jun 05 2016, Ford O. wrote:

> Don't make me angry.
>
> I have read that chapter more than 5 times.
> You could also read my question 5 times.
>
> I am asking why do we have to specify macro and function with different 
> keyword, when compiler exactly knows whether we are calling macro or 
> function.
>
> Example for ...:
> callable foo(e::Expr) = :()
> @foo 2 + 2
> foo(2 + 2)
> # two versions of foo callable are compiled, one as macro, one as function 
>
> Does the *macro *keyword have any significance for compiler?
>
> On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote:
>>
>> Sorry for linking a local version of the manual -- still, you could 
>> probably have found it with a bit of effort, but it appears that you are 
>> adamant in your refusal to read it. 
>>
>> I would say that the most important reasons is that macros have special 
>> conventions because of hygiene, see 
>> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene 
>>
>> Some languages (eg Common Lisp) have the same namespace for macros and 
>> functions, Julia distinguishes them with @. So they are not as seamless 
>> as in CL, but at the same time they stand out and warn the reader that 
>> source transformation is going on. There could be arguments for both 
>> choices, but Julia chose this one. 
>>
>> On Sun, Jun 05 2016, Ford O. wrote: 
>>
>> > You got it wrong. 
>> > In different words. 
>> > 
>> > Why do we need to specify macro and function block with macro and 
>> function 
>> > keyword? Isnt the '@' symbol enough? 
>> > 
>> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote: 
>> >> 
>> >> A macro is a function that is used to transform (a representation) of 
>> >> source code. Consequently, it is called when Julia evaluates your 
>> >> function defintions, not at runtime. Please read 
>> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
>> >> you find examples. 
>> >> 
>> >> Regarding you example: it is unclear what you are trying to do, but 
>> >> unless you use the macro keyword, you get an ordinary function, not a 
>> >> macro. 
>> >> 
>> >> On Sun, Jun 05 2016, Ford O. wrote: 
>> >> 
>> >> > What makes macro different from function? 
>> >> > 
>> >> > Why is it not possible to do: 
>> >> > foo(e::Expr) = :() 
>> >> > @foo x = x + 5 
>> >> > 
>> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
>> >> > 
>> >> >  I think this deserves an own topic. 
>> >> > 
>> >> >  You should post here syntax that looks like duplicate or you think 
>> it 
>> >> could use already existing keyword. (mark with # identical or # 
>> >> replacement) 
>> >> >  Rule of thumb - the less special syntax the better. 
>> >> > 
>> >> >  # identical 
>> >> >  # replace ' , ' with ' ; ' in arrays ? 
>> >> >  [1, 2, 3, 4] 
>> >> >  [1; 2; 3; 4] 
>> >> > 
>> >> >  # identical 
>> >> >  # replace ' = ' with ' in ' in for loops ? 
>> >> >  for i = 1:10 
>> >> >  for i in 1:10 
>> >> > 
>> >> >  # replacement 
>> >> >  # replace ' -> ' with ' = ' in anonymous functions ? 
>> >> >  (a, b, c) -> a + b + c 
>> >> >  (a, b, c) = a + b + c 
>> >> 
>> >> 
>>
>>



Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
Don't make me angry.

I have read that chapter more than 5 times.
You could also read my question 5 times.

I am asking why do we have to specify macro and function with different 
keyword, when compiler exactly knows whether we are calling macro or 
function.

Example for ...:
callable foo(e::Expr) = :()
@foo 2 + 2
foo(2 + 2)
# two versions of foo callable are compiled, one as macro, one as function 

Does the *macro *keyword have any significance for compiler?

On Sunday, June 5, 2016 at 1:38:32 PM UTC+2, Tamas Papp wrote:
>
> Sorry for linking a local version of the manual -- still, you could 
> probably have found it with a bit of effort, but it appears that you are 
> adamant in your refusal to read it. 
>
> I would say that the most important reasons is that macros have special 
> conventions because of hygiene, see 
> http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene 
>
> Some languages (eg Common Lisp) have the same namespace for macros and 
> functions, Julia distinguishes them with @. So they are not as seamless 
> as in CL, but at the same time they stand out and warn the reader that 
> source transformation is going on. There could be arguments for both 
> choices, but Julia chose this one. 
>
> On Sun, Jun 05 2016, Ford O. wrote: 
>
> > You got it wrong. 
> > In different words. 
> > 
> > Why do we need to specify macro and function block with macro and 
> function 
> > keyword? Isnt the '@' symbol enough? 
> > 
> > On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote: 
> >> 
> >> A macro is a function that is used to transform (a representation) of 
> >> source code. Consequently, it is called when Julia evaluates your 
> >> function defintions, not at runtime. Please read 
> >> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
> >> you find examples. 
> >> 
> >> Regarding you example: it is unclear what you are trying to do, but 
> >> unless you use the macro keyword, you get an ordinary function, not a 
> >> macro. 
> >> 
> >> On Sun, Jun 05 2016, Ford O. wrote: 
> >> 
> >> > What makes macro different from function? 
> >> > 
> >> > Why is it not possible to do: 
> >> > foo(e::Expr) = :() 
> >> > @foo x = x + 5 
> >> > 
> >> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
> >> > 
> >> >  I think this deserves an own topic. 
> >> > 
> >> >  You should post here syntax that looks like duplicate or you think 
> it 
> >> could use already existing keyword. (mark with # identical or # 
> >> replacement) 
> >> >  Rule of thumb - the less special syntax the better. 
> >> > 
> >> >  # identical 
> >> >  # replace ' , ' with ' ; ' in arrays ? 
> >> >  [1, 2, 3, 4] 
> >> >  [1; 2; 3; 4] 
> >> > 
> >> >  # identical 
> >> >  # replace ' = ' with ' in ' in for loops ? 
> >> >  for i = 1:10 
> >> >  for i in 1:10 
> >> > 
> >> >  # replacement 
> >> >  # replace ' -> ' with ' = ' in anonymous functions ? 
> >> >  (a, b, c) -> a + b + c 
> >> >  (a, b, c) = a + b + c 
> >> 
> >> 
>
>

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Tamas Papp
Sorry for linking a local version of the manual -- still, you could
probably have found it with a bit of effort, but it appears that you are
adamant in your refusal to read it.

I would say that the most important reasons is that macros have special
conventions because of hygiene, see
http://docs.julialang.org/en/release-0.4/manual/metaprogramming/#hygiene

Some languages (eg Common Lisp) have the same namespace for macros and
functions, Julia distinguishes them with @. So they are not as seamless
as in CL, but at the same time they stand out and warn the reader that
source transformation is going on. There could be arguments for both
choices, but Julia chose this one.

On Sun, Jun 05 2016, Ford O. wrote:

> You got it wrong.
> In different words.
>
> Why do we need to specify macro and function block with macro and function 
> keyword? Isnt the '@' symbol enough?
>
> On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote:
>>
>> A macro is a function that is used to transform (a representation) of 
>> source code. Consequently, it is called when Julia evaluates your 
>> function defintions, not at runtime. Please read 
>> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
>> you find examples. 
>>
>> Regarding you example: it is unclear what you are trying to do, but 
>> unless you use the macro keyword, you get an ordinary function, not a 
>> macro. 
>>
>> On Sun, Jun 05 2016, Ford O. wrote: 
>>
>> > What makes macro different from function? 
>> > 
>> > Why is it not possible to do: 
>> > foo(e::Expr) = :() 
>> > @foo x = x + 5 
>> > 
>> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
>> > 
>> >  I think this deserves an own topic. 
>> > 
>> >  You should post here syntax that looks like duplicate or you think it 
>> could use already existing keyword. (mark with # identical or # 
>> replacement) 
>> >  Rule of thumb - the less special syntax the better. 
>> > 
>> >  # identical 
>> >  # replace ' , ' with ' ; ' in arrays ? 
>> >  [1, 2, 3, 4] 
>> >  [1; 2; 3; 4] 
>> > 
>> >  # identical 
>> >  # replace ' = ' with ' in ' in for loops ? 
>> >  for i = 1:10 
>> >  for i in 1:10 
>> > 
>> >  # replacement 
>> >  # replace ' -> ' with ' = ' in anonymous functions ? 
>> >  (a, b, c) -> a + b + c 
>> >  (a, b, c) = a + b + c 
>>
>>



Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
You got it wrong.
In different words.

Why do we need to specify macro and function block with macro and function 
keyword? Isnt the '@' symbol enough?

On Sunday, June 5, 2016 at 1:11:48 PM UTC+2, Tamas Papp wrote:
>
> A macro is a function that is used to transform (a representation) of 
> source code. Consequently, it is called when Julia evaluates your 
> function defintions, not at runtime. Please read 
> file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where 
> you find examples. 
>
> Regarding you example: it is unclear what you are trying to do, but 
> unless you use the macro keyword, you get an ordinary function, not a 
> macro. 
>
> On Sun, Jun 05 2016, Ford O. wrote: 
>
> > What makes macro different from function? 
> > 
> > Why is it not possible to do: 
> > foo(e::Expr) = :() 
> > @foo x = x + 5 
> > 
> > On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote: 
> > 
> >  I think this deserves an own topic. 
> > 
> >  You should post here syntax that looks like duplicate or you think it 
> could use already existing keyword. (mark with # identical or # 
> replacement) 
> >  Rule of thumb - the less special syntax the better. 
> > 
> >  # identical 
> >  # replace ' , ' with ' ; ' in arrays ? 
> >  [1, 2, 3, 4] 
> >  [1; 2; 3; 4] 
> > 
> >  # identical 
> >  # replace ' = ' with ' in ' in for loops ? 
> >  for i = 1:10 
> >  for i in 1:10 
> > 
> >  # replacement 
> >  # replace ' -> ' with ' = ' in anonymous functions ? 
> >  (a, b, c) -> a + b + c 
> >  (a, b, c) = a + b + c 
>
>

Re: [julia-users] Re: Uniform syntax

2016-06-05 Thread Tamas Papp
A macro is a function that is used to transform (a representation) of
source code. Consequently, it is called when Julia evaluates your
function defintions, not at runtime. Please read
file:///usr/share/doc/julia-doc/html/manual/metaprogramming.html where
you find examples.

Regarding you example: it is unclear what you are trying to do, but
unless you use the macro keyword, you get an ordinary function, not a
macro.

On Sun, Jun 05 2016, Ford O. wrote:

> What makes macro different from function?
>
> Why is it not possible to do:
> foo(e::Expr) = :()
> @foo x = x + 5
>
> On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote:
>
>  I think this deserves an own topic.
>
>  You should post here syntax that looks like duplicate or you think it could 
> use already existing keyword. (mark with # identical or # replacement)
>  Rule of thumb - the less special syntax the better.
>
>  # identical
>  # replace ' , ' with ' ; ' in arrays ?
>  [1, 2, 3, 4]
>  [1; 2; 3; 4]
>
>  # identical
>  # replace ' = ' with ' in ' in for loops ?
>  for i = 1:10
>  for i in 1:10
>
>  # replacement
>  # replace ' -> ' with ' = ' in anonymous functions ?
>  (a, b, c) -> a + b + c
>  (a, b, c) = a + b + c



[julia-users] Re: Uniform syntax

2016-06-05 Thread Steven G. Johnson


On Sunday, June 5, 2016 at 6:35:48 AM UTC-4, Ford O. wrote:
>
> What makes macro different from function?
>

Macros are executed at parse time.  Functions are executed at runtime. 


[julia-users] Re: Help creating user-defined types and constructors

2016-06-05 Thread Christopher Fisher
Thanks again for the all of the advice. The Julia community is very 
helpful.  I should be able to figure out a viable solution.


[julia-users] Re: Uniform syntax

2016-06-05 Thread Ford O.
What makes macro different from function?

Why is it not possible to do:
foo(e::Expr) = :()
@foo x = x + 5

On Friday, June 3, 2016 at 10:05:46 AM UTC+2, Ford O. wrote:
>
> I think this deserves an own topic.
>
> *You* should post here syntax that looks like duplicate or you think it 
> could use already existing keyword. (mark with* # identical *or *# 
> replacement*)
> Rule of thumb - *the less special syntax the better*.
>
> # identical
> # replace ' , ' with ' ; ' in arrays ?
> [1, 2, 3, 4]
> [1; 2; 3; 4]
>
>
>
> # identical
> # replace ' = ' with ' in ' in for loops ?
> for i = 1:10
> for i in 1:10
>
>
>
>
> # replacement
> # replace ' -> ' with ' = ' in anonymous functions ?
> (a, b, c) -> a + b + c
> (a, b, c) = a + b + c
>


[julia-users] Julia Plugins

2016-06-05 Thread Leonardo
Hi all,
I want realize a pluggable architecture in Julia, loading dinamically some 
precompiled code from any path (for sure functions, but also types, and 
maybe entire modules).
Excluding load of source files with include(), can I load some .ji file 
containing chunks of code (also encapulated in function, types, modules) or 
- better - some indipendent precompiled code (like llvm code instead native 
code)?

Many thanks in advance for your attention

Leonardo



[julia-users] Re: ANN: PkgSearch - a REPL utility for package discovery

2016-06-05 Thread Adrian Salceanu
Thanks for the feedback, happy to contribute. 


vineri, 3 iunie 2016, 22:40:50 UTC+2, Adrian Salceanu a scris:
>
> Hi, 
>
> I have released PkgSearch, a small REPL utility for package discovery. 
>
> Package discovery seemed to be a recurring issue, with many related 
> questions - and I can still remember how difficult was for me too, when I 
> started. So it might be a useful tool. 
> I've been using it for a few days and it's kind of neat, being able to 
> quickly search through all the publicly available packages without leaving 
> the REPL :) I hope you'll enjoy it! 
>
> It works in conjunction with an API which powers the actual search. On the 
> server side, a full text search is performed against the README files. It 
> covers both official packages and unofficial ones, searching for them on 
> GitHub (not in real time, the data is imported regularly). This GitHub 
> search is a bit naive still, so false positives might come up. 
>
> More details in the README, at https://github.com/essenciary/PkgSearch
>
> ===
>
> On a related note, the API providing the search results and all the 
> tooling for importing and processing the data is done with Genie (formerly 
> Jinnie) - the Julia web framework I've been working on for many months now. 
> It's not ready for prime time yet but this is definitely a major milestone! 
>
> With this occasion I've also added a very comprehensive README to give you 
> an idea about what it does, how it works and where it's heading. 
>
> You can find it here https://github.com/essenciary/genie - and if you 
> like it, please star it :) 
>
> Cheers,
> Adrian
>


[julia-users] Re: Help creating user-defined types and constructors

2016-06-05 Thread Ford O.
I want to discourage you from using symbols because although it perfectly 
works for you right now, but you might get into trouble later.

Lets say you want to add an array into Population and you want to keep 
symbol indexing:
Population
  persons
  newarray
end
#You can't do population[:newarray, index]
#Unless you rewrite your code and change population[:persons, :attribute, 
index]

Or you decide, that you wanna make new interface:
population[:persons, index]
population[:attribute, index]
population[index] # throws error 
This also wont be possible, so you end up rewriting all your code.

I wish it would be possible to do this in julia
setindex!(population, value, ::Individual, index...) = population.
individuals[index...] = value
setindex!(population, value, ::Infected, index...) = population.individuals[
index...].infected = value
population[::Individual, 1] = Individual()
population[::Infected,   1] = true
# Note that I have not declared Infected type anywhere

Which would eliminate all kind of problems, but I am not sure it's codeable 
or wanted in the first place.

So since this is not possible, I would stick to classical functions, as I 
showed you in the very first post in this discussion.


On Sunday, June 5, 2016 at 7:06:32 AM UTC+2, Glenn Fulford wrote:
>
> Hi Christopher, 
> You are right, there are not many examples out there of using Julia for 
> agent based models, at least as far as I can see. 
>
> I am not sure if you know about this one, but in the excellent QuantEcon 
> website, they give an example of Schelling's model of segregation with some 
> example code.
>
> http://nbviewer.jupyter.org/github/QuantEcon/QuantEcon.applications/blob/master/schelling/schelling_solutions_jl.ipynb
>
> But I think maybe what you are trying to do is a little bit more than 
> this, but just thought I would mention this example in case you hadn't seen 
> it. 
> Glenn
>
>
> On Saturday, 4 June 2016 22:19:02 UTC+10, Christopher Fisher wrote:
>>
>> I was wondering if someone would be willing to help me with creating 
>> user-defined types. I've been using Julia for about two years now but I am 
>> new to the idea of creating custom types. I'm trying to create a population 
>> of agents/individuals in a simple epidemiological simulation. 
>>
>> type Person
>> infected::Int64
>> vaccinated::Int64
>> dead::Int64
>>history::Array{Int64,1}
>> end
>>
>> Any help would be greatly appreciated. 
>>
>