Earlier quoted context omitted.
FWIW, Raku and XPath support kebap-case. If you really mean subtraction, you have to add whitespace.
That works, but isn't necessary in Raku. As long as the right side of the hyphen does not start with an alphabetic character, you're good: my $a = 45; say $a-3; # 42
Microfeatures I'd like to see in more languages
421–430 of 539 posts
Re: Microfeatures I'd like to see in more languages
#422Earlier quoted context omitted.
Elixir has forward pipes, but didn't invent them. For instance Racket and Clojure have threading macros , which are more flexible as they're just macros (Clojure's `->` is equivalent to Elixir's pipe operator, but `->>` will fill in the last parameter rather than first, and `-->` lets you use a keyword to define where the parameter is inserted in each call). Haskell let anyone who wants define their own pipe operator…
The earliest I've seen |> specifically in stdlib was in F#, which still predates Elixir by several years.
Re: Microfeatures I'd like to see in more languages
#423Earlier quoted context omitted.
Also on a function? var getDate() { return „no date“; }
No, but I think that was a good choice. In local code this is great, but in an interface contract being explicit about data type is a virtue.
Re: Microfeatures I'd like to see in more languages
#424Re: Microfeatures I'd like to see in more languages
#425Earlier quoted context omitted.
> My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. To me, these are "Tell bar's foo to do something with baz." and "Tell foo to do something with bar and baz.". So being 'able' to flipflop the syntax is at least temporarily semantic'ly confusing.
Except I find the concept of state "doing something with" other state unhelpful. Why is bar working with baz and not baz working with bar? I struggle with this in Unity: Player.collect(PickUp) // this? PickUp.boost(Player) // ...or this? Instead, the code should describe the interaction between the two units of state: onCollide(Player, Pickup) If we structure our code like in the last example, it makes sense to weake…
What is the code driving it?
- looping over players to update them?
- looping over objects to update them?
- some other event loop?
I actually like the third least:
The first two tell me what is happening, but the third doesn’t — I could be colliding to block motion or I could be picking up.
Re: Microfeatures I'd like to see in more languages
#426WebGL's swizzling vector selectors.[1] Where v.x desugars as v[0], v.y as v[1]. Similarly for z and w. Also r,g,b,a. And they swizzle: v.rgb, v.xz, v.zx . So `v1.xy = v0.yx` reflects. [1] https://www.w3.org/TR/WGSL/#vector-access-expr
You can write functions like xyz(v) and that works well enough. Even better if you have ufcs or methods.
Re: Microfeatures I'd like to see in more languages
#427I'm partial to for-else-loops. They fit perfectly into languages with compound expression (produce a value from a break in the loop or from the else block). They don't come up that often, but when they do they're really the best solution.
I feel like it would work better with a more explicit keyword, but I don't know which one. `nobreak`?
Re: Microfeatures I'd like to see in more languages
#428Earlier quoted context omitted.
What exactly do you mean by "damned" here?
I am assuming the author is using it as one would use "wicked" (with a positive conotation)?
Not that I was completely innocent of this at that age.
/Rant.
Re: Microfeatures I'd like to see in more languages
#429Earlier quoted context omitted.
Nestable comment syntax is also nice. At least some MLs (eg SML) has it, that I know of. Indentation-sensitivity can also solve similar problems. (Indentation does not have to exclude requiring graphic termination. A formal language can require both. Or just a helpful tool.) (Also agree with 'kebab-case', although the name is new to me and a bit weird.)
What makes C-style comments unnestable?
Re: Microfeatures I'd like to see in more languages
#430Prolog has a weird third thing going on. Arithmetic only happens in specific contexts. i.e.
A is 4 - 2, % arithmetic, technically is(A,-(4,2)), A is 2
A #= 4 - 2, % arithmetic, A is 2
A = 4-2, % non arithmetic, A is unified with the term -(4,2) which pretty prints as 4-2
A = -2, % non arithmetic but A is the number -2 not a term -(2).
A = 4-2, B is 4 + A, % a weird one A is the term -(4,2) but when it gets called in the context is(B,+(4,A)) it gets treated as the arithmetic '-' and B is 6
you can also kebab-case predicate names so l-h-t(L,H,T) :- L = [H|T].
?- l-h-t([1,2,3,4],H,T). %works as desired
H = 1,
T = [2, 3, 4].
you can't do it with variables though.