Re: [julia-users] Re: Julian way to write longer if/elseif/else clauses?
(I'll double check, but Match.jl should also have zero overhead for those examples.) On Wed, May 7, 2014 at 2:00 PM, Cameron McBride wrote: > great! I'll check it out. > > Cameron > > > On Wed, May 7, 2014 at 8:01 AM, Mike Innes wrote: > >> If you need deeper pattern matching Match.jl is a great option, but you >> may also be interested in the @switch macro that lives in Lazy.jl – it >> will have zero overhead for cases like your example. >> >> https://github.com/one-more-minute/Lazy.jl#macros >> >> >> On Friday, 2 May 2014 15:11:08 UTC+1, Cameron McBride wrote: >>> >>> I'm still trying to settle into proper syntax and style, and all >>> comments are welcome! >>> >>> For potentially longer if / elseif / else clauses, e.g. >>> >>> # an overly simplistic example >>> if ndims(wt) == 2 >>>println("Matrix stuff") >>> elseif ndims(wt) == 1 >>>println("Vector stuff") >>> else >>>println("Scalar stuff") >>> end >>> >>> Multiple dispatch doesn't seem to help the specific case I have in mind, >>> as this is only a small part of the logic. >>> >>> This is perhaps as easy application of a case / switch statement, which >>> I don't think Julia has (I have ruby's case / when / else in mind). >>> >>> Even more general, is there any mechanism to do pattern matching (e.g. >>> 'match' in OCaml)? >>> >>> Cameron >>> >> >
Re: [julia-users] Re: Julian way to write longer if/elseif/else clauses?
great! I'll check it out. Cameron On Wed, May 7, 2014 at 8:01 AM, Mike Innes wrote: > If you need deeper pattern matching Match.jl is a great option, but you > may also be interested in the @switch macro that lives in Lazy.jl – it > will have zero overhead for cases like your example. > > https://github.com/one-more-minute/Lazy.jl#macros > > > On Friday, 2 May 2014 15:11:08 UTC+1, Cameron McBride wrote: >> >> I'm still trying to settle into proper syntax and style, and all comments >> are welcome! >> >> For potentially longer if / elseif / else clauses, e.g. >> >> # an overly simplistic example >> if ndims(wt) == 2 >>println("Matrix stuff") >> elseif ndims(wt) == 1 >>println("Vector stuff") >> else >>println("Scalar stuff") >> end >> >> Multiple dispatch doesn't seem to help the specific case I have in mind, >> as this is only a small part of the logic. >> >> This is perhaps as easy application of a case / switch statement, which I >> don't think Julia has (I have ruby's case / when / else in mind). >> >> Even more general, is there any mechanism to do pattern matching (e.g. >> 'match' in OCaml)? >> >> Cameron >> >
[julia-users] Re: Julian way to write longer if/elseif/else clauses?
If you need deeper pattern matching Match.jl is a great option, but you may also be interested in the @switch macro that lives in Lazy.jl – it will have zero overhead for cases like your example. https://github.com/one-more-minute/Lazy.jl#macros On Friday, 2 May 2014 15:11:08 UTC+1, Cameron McBride wrote: > > I'm still trying to settle into proper syntax and style, and all comments > are welcome! > > For potentially longer if / elseif / else clauses, e.g. > > # an overly simplistic example > if ndims(wt) == 2 >println("Matrix stuff") > elseif ndims(wt) == 1 >println("Vector stuff") > else >println("Scalar stuff") > end > > Multiple dispatch doesn't seem to help the specific case I have in mind, > as this is only a small part of the logic. > > This is perhaps as easy application of a case / switch statement, which I > don't think Julia has (I have ruby's case / when / else in mind). > > Even more general, is there any mechanism to do pattern matching (e.g. > 'match' in OCaml)? > > Cameron >
[julia-users] Re: Julian way to write longer if/elseif/else clauses?
See: https://github.com/JuliaLang/julia/issues/5410 for progress on a possible switch statement Also, I would probably recommend that you restructure your code so that you can use multiple dispatch. Your example is overly simple, so it is hard to tell you how to solve the problems that might arise. kl. 16:11:08 UTC+2 fredag 2. mai 2014 skrev Cameron McBride følgende: > > I'm still trying to settle into proper syntax and style, and all comments > are welcome! > > For potentially longer if / elseif / else clauses, e.g. > > # an overly simplistic example > if ndims(wt) == 2 >println("Matrix stuff") > elseif ndims(wt) == 1 >println("Vector stuff") > else >println("Scalar stuff") > end > > Multiple dispatch doesn't seem to help the specific case I have in mind, > as this is only a small part of the logic. > > This is perhaps as easy application of a case / switch statement, which I > don't think Julia has (I have ruby's case / when / else in mind). > > Even more general, is there any mechanism to do pattern matching (e.g. > 'match' in OCaml)? > > Cameron >