Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FlapYoJacks
Feb 12, 2009
Python 3.10 introduced case statements. It’s the best version.

Adbot
ADBOT LOVES YOU

Cybernetic Vermin
Apr 18, 2005

for/else seems plenty useful, but in exactly the same way goto is plenty useful. overly arbitrary control flow is what i'm saying.

cinci zoo sniper
Mar 15, 2013




DoomTrainPhD posted:

Python 3.10 introduced case statements. It’s the best version.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
but does it have for..case?

cinci zoo sniper
Mar 15, 2013




eschaton posted:

but does it have for..case?

the what now

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
python needs for...candles

BobHoward
Feb 13, 2012

The only thing white people deserve is a bullet to their empty skull
oh you want a what now, do you?

so in verilog you get case statements like this:

code:
int x;
case(x)
    1: // do something
    2: // do something else
    default: // complain
endcase
i assume everyone can work out what's going on there. but guess what motherfuckers??? this here's 100% legal verilog too:

code:
int x, y;
case(1)
    x: // do something
    y: // do something else
    default: // complain
endcase

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

BobHoward posted:

oh you want a what now, do you?

so in verilog you get case statements like this:

code:
int x;
case(x)
    1: // do something
    2: // do something else
    default: // complain
endcase
i assume everyone can work out what's going on there. but guess what motherfuckers??? this here's 100% legal verilog too:

code:
int x, y;
case(1)
    x: // do something
    y: // do something else
    default: // complain
endcase

if more than one is true does it invoke both?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

BobHoward posted:

oh you want a what now, do you?

so in verilog you get case statements like this:

code:
int x;
case(x)
    1: // do something
    2: // do something else
    default: // complain
endcase
i assume everyone can work out what's going on there. but guess what motherfuckers??? this here's 100% legal verilog too:

code:
int x, y;
case(1)
    x: // do something
    y: // do something else
    default: // complain
endcase

Will it do just x or x and y if they're both 1? Lmao just please don't tell me it will only do y

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
is that synthesizable?

TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE

BobHoward posted:

oh you want a what now, do you?

so in verilog you get case statements like this:

code:
int x;
case(x)
    1: // do something
    2: // do something else
    default: // complain
endcase
i assume everyone can work out what's going on there. but guess what motherfuckers??? this here's 100% legal verilog too:

code:
int x, y;
case(1)
    x: // do something
    y: // do something else
    default: // complain
endcase

maybe i'm missing something here but this doesn't seem that wacky to me? it's weird if you're used to c/c++, where the switch statement takes any expression but the case statement only takes constant expressions, but it's not that uncommon in other languages to allow any expression in either place. it's just a fancy way of writing a bunch of "if a == b" clauses so it doesn't matter which order you put the operands in.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

leper khan posted:

Will it do just x or x and y if they're both 1? Lmao just please don't tell me it will only do y

Just x

Don't see why it wouldn't be synthesizable, like TheFluff points out, it's basically just a bunch of else ifs chained together.

HappyHippo fucked around with this message at 16:19 on Feb 22, 2022

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

the for case paradigm

cinci zoo sniper
Mar 15, 2013





good god (i definitely can use that)

toiletbrush
May 17, 2010

leper khan posted:

Will it do just x or x and y if they're both 1? Lmao just please don't tell me it will only do y
you can do this in Swift, and it chooses the first match

seems like the right thing to do, tbh

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
see also Duff’s device, which is basically while…case

if you look at oldschool unix kernel, device driver, etc. code you might encounter it as a micro-optimization

Cybernetic Vermin
Apr 18, 2005

toiletbrush posted:

you can do this in Swift, and it chooses the first match

seems like the right thing to do, tbh

in swift sure, but for a logic description language it arguably would make at least as much sense to have all matching cases "happen" at once, but i guess that is not the way verilog does things.

BobHoward
Feb 13, 2012

The only thing white people deserve is a bullet to their empty skull

Sweeper posted:

if more than one is true does it invoke both?

IEEE 1800-2017 posted:

The case_expression shall be evaluated exactly once and before any of the case_item_expressions. The case_item_expressions shall be evaluated and then compared in the exact order in which they appear. If there is a default case_item, it is ignored during this linear search. During the linear search, if one of the case_item_expressions matches the case_expression, then the statement associated with that case_item shall be executed, and the linear search shall terminate. If all comparisons fail and the default item is given, then the default item statement shall be executed. If the default statement is not given and all of the comparisons fail, then none of the case_item statements shall be executed.

except... if you prefix the case statement with the "unique" keyword, this is an assertion that you think exactly one case item (not 0, not 2 or more) will match. this makes it safe to evaluate all branches of the case statement in parallel. this is quite useful for certain synthesizable constructs where you want to make the logic generated for each branch of the case fully independent from the rest, but it comes with some footguns. the synthesized HW is generated by assuming that you are correct to assert uniqueness, and won't do anything to protect you if multiple branches of the case statement match.

in a simulation, the simulator will throw an error if multiple matches occur when the unique case statement is evaluated, so you better make sure your sim has adequate coverage and never throws that error.

animist
Aug 28, 2018
if i were designing a programming language i would simply evaluate all the arguments at the same time

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
i feel like there's one of those formal proof languages that has the rule that if multiple branches match one is selected at random to be evaluated

my mind keeps telling me it's related to z, but i can't find an example of control flow in that

tinaun
Jun 9, 2011

                  tell me...
here's a rust quiz that's related

Rust code:
fn id(n: i32) {
    const X: i32 = 1;
    let y: i32 = 2;
    
    match n {
        X => println!("that's one"),
        y => println!("that's two"),
        _ => println!("something else"),
    }
}

fn main() {
    id(1);
    id(2);
    id(3);
}

gonadic io
Feb 16, 2011

>>=

Destroyenator posted:

i feel like there's one of those formal proof languages that has the rule that if multiple branches match one is selected at random to be evaluated

my mind keeps telling me it's related to z, but i can't find an example of control flow in that

go does this with channels

gonadic io
Feb 16, 2011

>>=

tinaun posted:

here's a rust quiz that's related

I got this correct lol, but I'm cheating because it comes up in haskell too. It is also a rustc warning!

code:
warning: unreachable pattern
 --> src/main.rs:8:9
  |
7 |         y => println!("that's two"),
  |         - matches any value
8 |         _ => println!("something else"),
  |         ^ unreachable pattern
  |
  = note: `#[warn(unreachable_patterns)]` on by default

warning: unused variable: `y`
 --> src/main.rs:3:9
  |
3 |     let y: i32 = 2;
  |         ^ help: if this is intentional, prefix it with an underscore: `_y`
  |
  = note: `#[warn(unused_variables)]` on by default

gonadic io fucked around with this message at 22:57 on Feb 22, 2022

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
swift doesn’t have that problem but i’m honestly not sure it was worth it because it’s sooo wordy having to write let in patterns

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Destroyenator posted:

i feel like there's one of those formal proof languages that has the rule that if multiple branches match one is selected at random to be evaluated

my mind keeps telling me it's related to z, but i can't find an example of control flow in that

dijkstra's "guarded command language" in a discipline of programming featured loops and conditionals which were each a set of clauses with "guard" preconditions, and they were intended to select a matching guard nondeterministically. the only difference between a conditional and a loop is that conditionals must have one matching clause, whereas loops iterate as long as there is at least one matching clause

Internet Janitor fucked around with this message at 03:38 on Feb 23, 2022

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

rjmccall posted:

swift doesn’t have that problem but i’m honestly not sure it was worth it because it’s sooo wordy having to write let in patterns

oh no the horror you might have to use more characters to express something that someone might have to read, understand, and change 30 years from now

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
whjust do what most MUMPS implementations do and what DCL does, and support using the minimum spelling that’s unambiguous at any point in the program!

Kazinsal
Dec 13, 2011


eschaton posted:

whjust do what most MUMPS implementations do and what DCL does, and support using the minimum spelling that’s unambiguous at any point in the program!

also applicable to cisco boxes

sw t p v e 1,2,3

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Internet Janitor posted:

dijkstra's "guarded command language" in a discipline of programming featured loops and conditionals which were each a set of clauses with "guard" preconditions, and they were intended to select a matching guard nondeterministically. the only difference between a conditional and a loop is that conditionals must have one matching clause, whereas loops iterate as long as there is at least one matching clause

that was it, thank you!

Cybernetic Vermin
Apr 18, 2005

eschaton posted:

oh no the horror you might have to use more characters to express something that someone might have to read, understand, and change 30 years from now

i for one add a "/* let */" in every place it is syntactically allowed in my programs, to help the people in 30 years.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Cybernetic Vermin posted:

i for one add a "/* let */" in every place it is syntactically allowed in my programs, to help the people in 30 years.

Knuth over here trying to solve illiteracy through writing.

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

casema balls

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

https://github.com/Kindelia/HVM

quote:

High-order Virtual Machine (HVM) is a pure functional compile target that is lazy, non-garbage-collected and massively parallel. It is also beta-optimal, meaning that, in several cases, it can be exponentially faster than most functional runtimes, including Haskell's GHC.

That is possible due to a new model of computation, the Interaction Net, which combines the Turing Machine with the Lambda Calculus. Previous implementations of this model have been inefficient in practice, however, a recent breakthrough has drastically improved its efficiency, giving birth to the HVM. Despite being a prototype, it already beats mature compilers in many cases, and is set to scale towards uncharted levels of performance.

Welcome to the inevitable parallel, functional future of computers!

I don’t know enough about Haskell or beta optimality or higher-kinded anything to really evaluate it, but I do know that cherry-picked benchmarks can even make a compiler I write look good

is this
  • so restricted in its computing model that there aren’t meaningful non-toy applications
  • some other flavour of kookery
  • actually promising
?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



idk that depends.... is it highly opinionated?

CPColin
Sep 9, 2003

Big ol' smile.
I'm sigma-optimal

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
i mean you can do a lot if you just completely assume purity. even haskell compilers have to model effects

gonadic io
Feb 16, 2011

>>=
This came up with STM too, with haskell (and co) the only ones to be able to implement it without insane footguns of: literally any side effect in code.

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe
sigma nutts

Nomnom Cookie
Aug 30, 2009



Subjunctive posted:

https://github.com/Kindelia/HVM

I don’t know enough about Haskell or beta optimality or higher-kinded anything to really evaluate it, but I do know that cherry-picked benchmarks can even make a compiler I write look good

is this
  • so restricted in its computing model that there aren’t meaningful non-toy applications
  • some other flavour of kookery
  • actually promising
?

the author is excited about something or other that enables even higher levels of typewank than have previously been achieved in efficient computations. there will probably be a shitload of publications citing this but aside from that who knows

Adbot
ADBOT LOVES YOU

akadajet
Sep 14, 2003


new ux people at work have decided to go from zepplin (which is good) to figma (which sucks)

so figma balls

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply