Swift has an interesting take on composition via protocols (note, it also
has the concept of single inheritance):
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
it avoids copying anything into the child class, but rather sets up
An OO approach is really just specifying an interface in a formal manner.
The second you write any type of interface, you always risk making a choice
that will haunt you down the road. I don't see the difference between:
class Foo {
float getX() { ... }
float getY() { ... }
}
and:
type
Ah, okay, that is different then. What's the advantage of creating a new
method versus copying the fields? I would imagine there is a penalty with
each deference you have to follow in order to make that work.
I'm not familiar with Scala, so sorry if I'm telling you something you
> know, but
I think this is generally in-line with what I've been advocating for, and
not that different from Scala's mix-ins:
trait Wheel {
// ...
}
trait Frame {
// ...
}
class Unicycle extends trait Wheel, Frame {
// ...
}
is essentially doing the same thing (i.e. copying the member variables
As for class composition, this is how Scala does it:
http://www.scala-lang.org/old/node/117
I've previously suggested introducing a `trait` label as to keep type and
dispatch information separate. Thus you could do:
trait A
x::Int64
y::Int64
end
trait B
z::Int64
end
type foo(A, B) <:
dispatch
> approach seems to me far better at addressing program maintainability and
> extensibility than classes ever were. Julia does still need a way of
> talking about interfaces and protocols in the language itself, but that's
> ongoing design problem, not a fundamental issue.
>
UTC-4, Tim Holy wrote:
>
> On Sunday, October 18, 2015 07:38:24 PM Abe Schneider wrote:
> > > Julia isn’t object-oriented, and will probably never be. But that
> doesn’t
> > > make it less powerful :)
> >
> > Of course it doesn't make it less powerful, bu
ted such a macro awhile ago (maybe a year?), and it was met with
disapproval. Not that that should stop anyone from writing it, but it was
deemed un-Julian (at least my take on people's responses). I think this can
be seen as a type of mix-in similar to what Ruby and Scala do.
>
> O
>
>
> But I agree with Tobias and Simon - there is very little reason to try to
> make Julia more object-oriented. All the power you get from OO is still
> there, but you might need to think a little differently to harness it. If
> you have a concrete problem, along the lines of “this is how
On Sunday, October 18, 2015 at 9:44:21 PM UTC-4, vav...@uwaterloo.ca wrote:
>
> Going a bit on a tangent, I claim that object-oriented programming, at
> least as embodied in C++, is not really suitable for scientific computing
> and in fact has led certain codes to go astray.
>
C++ is
I would say that the module is closest to a c++ namespace, which itself can
be thought of as a static class. Note, however, that in both cases you
can't really have separate instances.
Because of the desire to separate dispatch from type information, Julia
doesn't really follow the OOP
That's definitely an option, though it seems sub-optimal to me if it's
possible to automate it from a user's perspective. It may be that it just
isn't possible, but if so, is it because it's something the language
doesn't currently support or does it go against the philosophy of the
language?
to concretely suggest.
On Saturday, April 4, 2015 at 9:39:57 PM UTC-5, Abe Schneider wrote:
I don't understand how what I'm trying to do falls outside the domain of
transforming code. My main goal is to take a user-defined grammar and
create relevant code.
More to the point, I think
I should start off, not entirely sure this is an okay thing to do with
Julia. Suppose I want to create a macro that generates another macro, I can
write:
macro meta_macro(x)
quote
macro foo(y)
$x+y
end
end
end
and then call it and the generated macro:
@meta_macro(5)
` would generate the `@grammar` macro with the static
list it already has plus whatever else the user adds in.
Which works, except for the whole module issue.
Thanks,
A
On Saturday, April 4, 2015 at 12:41:27 PM UTC-4, Patrick O'Leary wrote:
On Saturday, April 4, 2015 at 9:04:10 AM UTC-5, Abe
special_foo( $(QuoteNode(syntax_tree) )
end
end
On Sat, Apr 4, 2015 at 8:05 PM Abe Schneider abe.sc...@gmail.com
javascript: wrote:
The issue I'm dealing with is that I have a macro that I want to pass a
list of functions that the macro can employ for parsing grammars
(:block, rule.action))
push!(code, Expr(:escape, Expr(:(=), dot, fn)))
end
end
which seems to do the trick.
On Monday, March 23, 2015 at 8:00:23 AM UTC-4, Abe Schneider wrote:
Okay, I think I almost have a solution. I now collect all the actions from
the rules with the function
doAction(expr)
return parseDefinition(..., expr, ...)
end
On Sun, Mar 22, 2015 at 8:15 AM Abe Schneider abe.schnei...@gmail.com
http://mailto:abe.schnei...@gmail.com wrote:
I'm in the process of trying to figure out how to do something similar to
that, but it's unfortunately not easy. I
. so for the example above, rather
than directly assigning expr.args[2] into rule.action, you would return
the equivalent expression (quote; rule.action = $(expr.args[2]); end)
that do that operation at runtime
On Sun, Mar 22, 2015 at 11:01 PM Abe Schneider abe.schnei...@gmail.com
http
I'm in the process of trying to figure out how to do something similar to
that, but it's unfortunately not easy. I was hoping that there might be a
method to insert an expression into the AST without an eval required, as it
would greatly simplify the code Jameson suggested using the `insert`
Sorry, when I said AST, I meant the code that gets executed. A macro, at
least the way I think about it, is inserting the resulting Expr into the
main AST.
My macro's primary role is to create a dictionary mapping symbols to
`Node`s. Each Node has an associated action (passed in with the curly
that takes `val` in as an argument and returns some new expression
(which you can then combine with other expressions before returning the
whole thing from the main macro)
On Wed, Mar 18, 2015 at 9:51 AM Abe Schneider abe.schnei...@gmail.com
http://mailto:abe.schnei...@gmail.com wrote
I have, but it's not entirely clear to me how I would use it in this
particular case. The code in question is being called from a function
(which while ultimately is being called from a macro) doesn't directly
return an expression in this case. Specifically, I have something that
looks like:
with other expressions before returning the
whole thing from the main macro)
On Wed, Mar 18, 2015 at 9:51 AM Abe Schneider abe.schnei...@gmail.com
http://mailto:abe.schnei...@gmail.com wrote:
Unfortunately my solution only works if you pass in an expression
directly. If you try something like
UTC-4, Isaiah wrote:
See
http://docs.julialang.org/en/release-0.3/manual/metaprogramming/#interpolation
On Mar 18, 2015 8:08 AM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
If I do something simple like:
macro test()
:(parsefloat(3.1459))
end
@test()
# 3.1459
everything
If I do something simple like:
macro test()
:(parsefloat(3.1459))
end
@test()
# 3.1459
everything works as expected. However, if I try this instead:
macro test2(ex)
ex
end
@test2(:(parsefloat(3.1459)))
# :(parsefloat(3.1459))
Not what I expected, but it makes sense what's happening:
2: ASCIIString 3.1459
typ: Any
So I can rewrite the macro as:
macro test2(ex)
ex.args[1]
end
which appears to work:
@test2(:(parsefloat(3.1459)))
# 3.1459
On Wednesday, March 18, 2015 at 8:08:35 AM UTC-4, Abe Schneider wrote:
If I do something simple like:
macro test
did
before.in the main macro.
On Wednesday, March 18, 2015 at 9:30:32 AM UTC-4, Abe Schneider wrote:
After some thought, I realized that the easiest way to unquote is to reach
inside the Expr and pull out what is needed. If I do a dump of `ex` I get:
Expr
head: Symbol quote
args
).
-
alternatively, you could recurse through their expr code and replace all
variables of the form `_(\d+)` with :(children[\1])
-
On Fri, Mar 6, 2015 at 9:30 PM Abe Schneider abe.schnei...@gmail.com
http://mailto:abe.schnei...@gmail.com wrote:
Hmmm, good to know. Thank you.
The rationale
it more
succinctly by templating the redundant parts.
if you want a set or numbered list, use a set or number list.
variables are bad at that sort of task. whereas an Array is very good at it.
On Fri, Mar 6, 2015 at 8:05 AM Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I'm trying
I'm trying to create a set of variables (_1, _2, ...) from items within a
list in a macro. I have a (much) condensed version of the code:
macro testfn()
quote
i = 1
value = [1, 2, 3]
$(Expr(:(=), Expr(:symbol, Expr(:string, _, :i)), :value))
println(_1)
I was recently thinking about the nature of `=` of not being an operator.
The reason given is that it sets the binding of the variable, rather than
the value. It seems like it would be nice to have an operator that dealt
with values rather than bindings. The reason being: (a) if it's an
Don't worry, I'm not re-opening the currently debated issue . It occurred
to me a while ago that it should be possible to support this feature
without any changes to the language itself.
Instead I've created the macros `@_abstract`, `@_type`, and `@_immutable`.
The idea is that `@_abstract`
You can think of a Task like a function that maintains state automatically.
However, instead of using returning values with 'return x', you use
'produce(x)' instead.
This will cause execution of the Task to pause until it is called again. Tasks
are called with the 'consume' function, which
It may be worth having both around. If you wrap the stateless versions with
something that keeps state, users get the choice of which one to use.
For example, you could use Tasks to create generators that produce the next
value. The Task will keep the state for you, which allows you to keep
For anyone who is interested, I've been working on a Grammatical Evolution
(GE) [Conor Ryan, JJ Collins and Michael O'Neill, 1998]
http://en.wikipedia.org/wiki/Grammatical_evolution#cite_note-1 library:
https://github.com/abeschneider/GrammaticalEvolution
It is not quite ready to reach version
Here's a quick test:
function make_counter(x)
return (delta) - begin
x += delta
x
end
end
c0 = make_counter(0)
c1 = make_counter(0)
c0(1) # 1
c1(1) # 1
c0(1) # 2
c1(1) # 2
So it looks like they don't share the bound 'x' variable.
On Friday, August 15, 2014 11:50:03 AM UTC-4, Noah
), which is why they generally don't
have access to the environment.
On Friday, August 1, 2014, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I tried a second approach where instead of keeping a function around I
keep just the symbol. I have a `transform` function that applies
I found one previous conversation related to this, but unfortunately the
answer didn't work for me. Hopefully I'm not asking an obvious question.
Suppose I have some macro:
macro mytest(fn::Symbol, ex::Expr)
quote
$(esc(fn))($ex)
end
end
and I have some function that takes in the
.
--Tim
On Sunday, August 03, 2014 11:46:43 AM Abe Schneider wrote:
I found one previous conversation related to this, but unfortunately the
answer didn't work for me. Hopefully I'm not asking an obvious question.
Suppose I have some macro:
macro mytest(fn::Symbol, ex::Expr
I've come across a problem where I have macro to define a grammar (similar
to how PEGParser currently works):
@grammar foo begin
rule[fn] = some + (rule | test)
end
where the `[fn]` next to the rule defines a function to call on the results
(in this case it's an expansion). The issue is
)) wherever you were previously using $fn
On Friday, August 1, 2014 11:38:44 AM UTC-4, Abe Schneider wrote:
That's correct, I'm generating code that keeps a pointer to that function
to call later on.
If I do that, I have the type `esc(fn)` in the macro (this is what I get
when printing it out
the macro, I could then just get the macro that way.
I'm guessing Julia doesn't currently have this functionality, but would it
be something possible to add?
On Friday, August 1, 2014 12:22:46 PM UTC-4, Abe Schneider wrote:
I think the problem is that I'm not accessing it directly through
I have a pattern that has come up multiple times where in a module I might
have some function `foo` which will call some other function `bar` on a
given type. The exact function `bar` isn't defined yet because it is
defined by the user-type. The problem I run into is that if `bar` is
defined
Thank you. If I do:
function testmodule.bar(baz::ConcreteBaz)
return baz.value
end
it works. I'm guessing this means that Julia won't look outside of the
namespace for a function.
It hadn't occurred to me that writing:
function module.fn()
# ...
end
would work.
On Saturday, July 26,
If you're interested, PEGParser includes a lisp grammar in the examples
section. The transform converts to Julia expressions, but that can easily be
changed.
It wasn't obvious to me initially why `sort` wasn't working for me (strings
and composite types). On further investigation it looks like that it only
works for single-dimension arrays -- which makes sense. However, if I type:
lst = [a b c]
sort(lst)
I get an error. The answer is that it's of
4, 2014, at 11:09 AM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I got sidetracked by a couple of other things, but the parser is now
updated with a bunch of bug fixes. I have a preliminary CSV and graphdot
parser (very reduced from the full grammar). I'm starting to put together
files.
After a few more tests are written, I'm getting ready to officially call a
version 0.1.
On Thursday, June 5, 2014 6:56:37 AM UTC-4, Abe Schneider wrote:
I also forgot to push the changes last night.
On Wednesday, June 4, 2014 11:01:33 PM UTC-4, Abe Schneider wrote:
After playing
://github.com/JuliaLang/julia/issues/4935.
On Jun 21, 2014, at 9:59 AM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I think that's a fair point (though I may disagree that it's
non-othogonal). My main point is that you are already implicitly using a
hierarchical structure
, 21. Juni 2014 03:43:57 UTC+2 schrieb Abe Schneider:
I agree, I think it's the best solution given the tools (and what I'm
going to use for my code). However, it still feels more like a hack around
the design than good programming practice.
On Friday, June 20, 2014 5:41:02 PM UTC-4, Spencer
more than why not?
On Jun 21, 2014, at 8:45 AM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
After some thought, it occurred to me that with the grouping you
suggested, you are really implementing a type of inheritance. If you rename
your sub-type as 'parent' you have:
type
are in the current view
private.
You might be also interested in
https://github.com/JuliaLang/julia/issues/6975 where we discuss how to
define interfaces more formally as it is done now.
Cheers,
Tobi
Am Freitag, 20. Juni 2014 04:15:21 UTC+2 schrieb Abe Schneider:
Okay, so
It's good to see other people want multiple inheritance too :).
One thing I haven't seen discussion yet is using Scala's method of constructors
to make deal with the fields and MI.
It seems like abstract types could be equivalent to Scala traits (if abstract
types allowed fields), and regular
I was thinking something along those lines, but as was pointed out, you would
have to also create the constructors.
Unfortunately, I'm on my phone right now, so I can't effectively post code. I
was thinking of a 'mixin' macro which would create a new type (with
constructor):
@mixin Foo : Bar
I was thinking something along those lines, but as was pointed out, you would
have to also create the constructors.
Unfortunately, I'm on my phone right now, so I can't effectively post code. I
was thinking of a 'mixin' macro which would create a new type (with
constructor):
@mixin Foo : Bar
. Most
importantly, it does it in really easy-to-reason-about way, without adding
any tricky edge cases or complicated rules for developers to understand.
peace,
s
On Fri, Jun 20, 2014 at 3:57 PM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I was thinking something along those
I'm trying to figure out the best way to factor code that consists of
repeated modules which all share some common attributes.
Specifically, if I have (very abbreviated from actual code):
abstract NNModule
type LinearModule : NNModule
weight::Array{Float64}
output::Array{Float64}
end
type
this line
type LinearModule : NNModule
weight::Array{Float64}
output::Array{Float64}
end
type SigmoidModule : NNModule
output::Array{Float64}
end
On Thu, Jun 19, 2014 at 8:18 AM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I'm trying to figure out the best way to factor
Abe Schneider wrote:
I was looking for a way to display a simulation in Julia. Originally I
was
going to just use PyPlot, but it occurred to me it would be better to
just
use Gtk+ + Cairo to do the drawing rather than something whose main
purpose
is drawing graphs.
So far
AM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
Thank you everyone for the fast replies!
After looking at ImageView and the sources, here's the solution I came up
with:
w = Gtk.@Window() |
(body=Gtk.@Box(:v) |
(canvas=Gtk.@Canvas(600, 600)) |
showall
function redraw_canvas
(canvas, myscene)
A
On Tuesday, June 17, 2014 1:16:11 PM UTC-4, Jameson wrote:
Yes. Although I think the draw...do function is actually redraw...do
(this is actually a shared interface with Tk.jl, although I recommend Gtk :)
Sent from my phone.
On Tuesday, June 17, 2014, Abe Schneider abe.sc
I was looking for a way to display a simulation in Julia. Originally I was
going to just use PyPlot, but it occurred to me it would be better to just
use Gtk+ + Cairo to do the drawing rather than something whose main purpose
is drawing graphs.
So far, following the examples on the Github
julia typeof(ans)
SubString{ASCIIString} (constructor with 1 method)
Which is totally understandable, as there seems to be almost zero
documentation about them. Would you mind opening an issue about that?
Cheers,
Kevin
On Wed, Jun 11, 2014 at 5:08 AM, Abe Schneider abe.sc...@gmail.com
I think that could also work. I prefer keeping that same syntax for regular
strings (the square-brackets make things easier to read). I'm assuming
strings don't normally return views because their contents could change,
thus copies are safer. That's why I'm suggesting creating an
I also forgot to push the changes last night.
On Wednesday, June 4, 2014 11:01:33 PM UTC-4, Abe Schneider wrote:
After playing around with a bunch of alternatives, I think I've come up
with decent action semantics:
@transform name begin
label = action
end
For example, a simple graph
/testscript.jl, in expression starting on
line 9
but if I define foo in the module (the commented out line), I get:
fn1 = 3
fn2 = 2
On Tuesday, June 3, 2014 9:59:25 PM UTC-4, Abe Schneider wrote:
I have a macro that is defined in a module that creates a dictionary of
anonymous functions
I should add, I suspect that 'esc' can only be used in a quote block, so I
tried this instead:
macro wrapexpr(expr)
quote
($(esc(x)), $(esc(y))) - $(esc(expr))
end
end
But get:
ERROR: x not defined
On Wednesday, June 4, 2014 11:44:43 AM UTC-4, David Moon wrote:
I have a pending
I got it to work with:
macro wrapexpr(expr)
x = :x
y = :y
quote
$(esc(quote ($x, $y) - $expr end))
end
end
I think the problem before was that the entire anonymous function has to be
escaped. I also don't claim to understand hygiene well enough to really
understand what that means.
.
There's a bunch of test files in the DataFrames.jl/test directory.
-- John
On May 27, 2014, at 3:49 PM, Abe Schneider abe.sc...@gmail.com
javascript: wrote:
I don't know how the speed of the parser will be compared to DataFrames --
I've done absolutely no work to date on profiling the code
better if they can be immutable.
thanks,
andrew
On Saturday, 31 May 2014 21:10:37 UTC-4, Abe Schneider wrote:
I should add that PEGParser's code is fairly new and untested (besides
having an uninspired name). I'm also hoping to have better action
semantics soon.
On Saturday, May 31
, andrew cooke wrote:
On Tuesday, 3 June 2014 08:16:49 UTC-4, Abe Schneider wrote:
Currently it only handles strings. The reason is that PEG theoretically
have infinite look-ahead. I think this can be made a little better by
having a stream that loads data on-demand. In general, I think PEG's
I have a macro that is defined in a module that creates a dictionary of
anonymous functions. These anonymous functions wrap arbitrary code which I
pass in. If I pass in simple pieces of code (e.g. just returning a simple
value), my test script everything works as expected.
However, if I make
I should add that PEGParser's code is fairly new and untested (besides
having an uninspired name). I'm also hoping to have better action
semantics soon.
On Saturday, May 31, 2014 2:17:27 PM UTC-4, andrew cooke wrote:
https://groups.google.com/d/msg/julia-users/t56VxOX1vvk/nszQYWP_pm4J
I don't know how the speed of the parser will be compared to DataFrames --
I've done absolutely no work to date on profiling the code, but I thought
writing a CSV parser was a good way to test out code (and helped find a
bunch of bugs).
I've also committed (under examples/) the CSV parser. The
I'll take a look. I found the full grammar here:
http://www.graphviz.org/doc/info/lang.html
Unfortunately I have very little free time (most of the work was done
during vacation), but it shouldn't be too difficult to implement.
On Monday, May 26, 2014 4:35:52 PM UTC-4, Miles Gould wrote:
I wrote a quick PEG Parser for Julia with Packrat capabilities:
https://github.com/abeschneider/PEGParser
It's a first draft and needs a ton of work, testing, etc., but if this is
of interest to anyone else, here is a quick description.
Grammars can be defined using most of the standard EBNF
I'm currently working on a problem where I have a tree structure composed
of:
type Node
value
label
children
end
which I want to traverse and have different functions called depending on
the value of label. Normally I would just sub-type Node. However, the
results are coming from a
I might try something like (note the code code is written for clarity, not
for compactness or completeness):
function encode_name(name::String)
if name == setosa
return [1 0 2];
elseif name == versicolor
return [2 1 0];
else
return [0 2 1];
end
end
output = map(encode_name,
the example again to check
it's behaving in the expected way?
On Thursday, 15 May 2014 12:29:13 UTC+1, Abe Schneider wrote:
As an experiment I wrote a simple macro to set a variable:
macro createVar(name, value)
eval(quote
$name = $value;
end)
end
which works as expected
to `expr = (foo = 5)`, *not* `expr = :(foo = 5)`
expr == 5
If you do want `createVar` to return an expression, it should be a
function instead of a macro. Maybe try running the example again to check
it's behaving in the expected way?
On Thursday, 15 May 2014 12:29:13 UTC+1, Abe Schneider
Just in terms of implementing trees, I would do something like:
abstract Node;
type Leaf : Node
value::Float64;
end
type Branch : Node
left::Node;
right::Node;
end
This should allow you to write methods that target either branch or leafs
accordingly:
function
82 matches
Mail list logo