News for hackers. Stuff that matters.
Re:Amber – the programming language compiled to Bash by zxexz on Wednesday May 22, 2024 @02:42AM (#40437993)
I was more put off more by the initial example. Amber being used to calculate an age being less than 18. With sed. Seems almost like an attempt at humor, except the bit where one would laugh.
Re:Amber – the programming language compiled to Bash by forgotpwd16 on Wednesday May 22, 2024 @04:10AM (#40438532)
This is the compiled to Bash part. Sed is used because `bc -l` can return a float when integer is expected. Not sure if can be done better in generic case but it isn't unheard. Certainly can be optimized for some cases. (Here e.g. can use Bash's built-in integer arithmetic.)
Re:Amber – the programming language compiled to Bash by kwhitefoot on Wednesday May 22, 2024 @04:35AM (#40438720)
But why does it use bc in the first place? Bash does integer arithmetic perfectly well on its own.

Amber claims to be type safe so it should have enough information to avoid the the use of bc in this case.

Ah, just looked at the documentation. Amber doesn't have integer types just a number type. That means that any numerical operation in Amber is pretty much guaranteed to be very inefficient.

It's a very strange choice to make because the underlying 'machine code' supports both integers and floating point.

Re:Amber – the programming language compiled to Bash by wrasee on Wednesday May 22, 2024 @07:11AM (#40439592)
This is the first thing I noticed. Using ‘bc’ and ‘sed’ for integer comparison seems quite odd.

But then they chose this for their front page example, the one that everyone will see, so I assumed this was to demonstrate something clever I just didn’t understand.

I wonder what the motivation was to not have an integer type?

Re:Amber – the programming language compiled to Bash by queuebert on Wednesday May 22, 2024 @10:34AM (#40441525)
You could also do the extremely readable `| cut -f1 -d.` which will do nothing for an integer.
Re:Amber – the programming language compiled to Bash by ape4 on Wednesday May 22, 2024 @10:45AM (#40441641)
Its ugly code - why would they show it off.