Giter VIP home page Giter VIP logo

switch.jl's Introduction

Switch.jl

Build Status Coverage Status

This package defines a C-style switch statement for Julia.

The basic definition uses @switch, @case, @default, and break.

using Switch

function f(x)
    @switch x begin
        @case 1
            print("one")
            break

        @case 2
            println("two")
            break

        @case 3
            println("three")
            break

        @default
            println("Can't count that high.")
    end
end

f(2) # → two
f(10) # → Can't count that high.

Without the break statements, case blocks fall through to the next block.

using Switch

function f(x)
    @switch x begin
        @case 1
            print("one")

        @case 2
            println("two")

        @case 3
            println("three")

        @default
            println("Can't count that high.")
    end
end

f(2) # → two, three, Can't count that high.
f(10) # → Can't count that high.

switch.jl's People

Contributors

dcjones avatar iainnz avatar

Stargazers

Anton Oresten avatar Niclas F. Sturm avatar Ellis Valentiner avatar  avatar  avatar Kenta Sato avatar Shashi Gowda avatar Westley Argentum Hennigh-Palermo avatar

Watchers

 avatar James Cloos avatar  avatar  avatar  avatar

switch.jl's Issues

Info about upcoming removal of packages in the General registry

As described in https://discourse.julialang.org/t/ann-plans-for-removing-packages-that-do-not-yet-support-1-0-from-the-general-registry/ we are planning on removing packages that do not support 1.0 from the General registry. This package has been detected to not support 1.0 and is thus slated to be removed. The removal of packages from the registry will happen approximately a month after this issue is open.

To transition to the new Pkg system using Project.toml, see https://github.com/JuliaRegistries/Registrator.jl#transitioning-from-require-to-projecttoml.
To then tag a new version of the package, see https://github.com/JuliaRegistries/Registrator.jl#via-the-github-app.

If you believe this package has erroneously been detected as not supporting 1.0 or have any other questions, don't hesitate to discuss it here or in the thread linked at the top of this post.

Doesn't work with new syntax on Julia 0.5

I tried to use this package on Julia 0.5 and got the following error. Is this an easy fix?

Pkg.test("Switch")
INFO: Testing Switch
ERROR: LoadError: LoadError: syntax: { } vector syntax is discontinued
 in include_from_node1(::String) at ./loading.jl:488
 in eval(::Module, ::Any) at ./boot.jl:234
 in require(::Symbol) at ./loading.jl:415
 in include_from_node1(::String) at ./loading.jl:488
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
while loading /home/arora/.julia/v0.5/Switch/src/Switch.jl, in expression starting on line 7
while loading /home/arora/.julia/v0.5/Switch/test/runtests.jl, in expression starting on line 6
==========================================================================================[ ERROR: Switch ]===========================================================================================

failed process: Process(`/home/arora/src/julia_0.5/julia/usr/bin/julia -Cnative -J/home/arora/src/julia_0.5/julia/usr/lib/julia/sys.so --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=yes --compilecache=yes /home/arora/.julia/v0.5/Switch/test/runtests.jl`, ProcessExited(1)) [1]

======================================================================================================================================================================================================
ERROR: Switch had test errors
 in #test#61(::Bool, ::Function, ::Array{AbstractString,1}) at ./pkg/entry.jl:740
 in (::Base.Pkg.Entry.#kw##test)(::Array{Any,1}, ::Base.Pkg.Entry.#test, ::Array{AbstractString,1}) at ./<missing>:0
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}}, ::String) at ./file.jl:59
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./pkg/dir.jl:31
 in (::Base.Pkg.Dir.#kw##cd)(::Array{Any,1}, ::Base.Pkg.Dir.#cd, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./<missing>:0
 in #test#3(::Bool, ::Function, ::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
 in test(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258

Tag and release a new version for v0.4.

Hi,

The current release version (v0.0.1) always prints these warning messages:

WARNING: deprecated syntax "{}" at /Users/kenta/.julia/v0.4/Switch/src/Switch.jl:8.
Use "[]" instead.

I think this has already been fixed by 62ec1fe. Could you tag and release a new version for Julia v0.4?

Switch does not work for enums

A classic use of switch is to test a flag passed as a function argument. I think Julia suggests passing such flags using the @enum macro. But it appears that switch does not support enums?

Minimal code to reproduce the problem:

@enum test t=1 f=2

tester = t

@switch tester begin
  @case t
     println("1")
   break
   @case f
      println("2")
    break
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.