Live data from Hacker News

Julia as a CLI Calculator

krasjet.com

121–130 of 134 posts

Re: Julia as a CLI Calculator

#121

One of my main gripes about matlab and that Julia unfortunately adopted is the dot syntax. Any other symbol would have worked, but the dot is just way too easy to overlook. I think it is because it was initially developed for people primarily working with matrices. Most of the things I do is actually based around multidimensional arrays so when I do operations I almost always want element-wise operations. Unfortunate…

You can use the @. macro to dot an entire block.

I personally like the dot syntax. It's ergonomic, and provides cool stuff like this: https://julialang.org/blog/2017/01/moredots/

I don't know of an equivalent functionality in any other language.

Re: Julia as a CLI Calculator

#123

One of my main gripes about matlab and that Julia unfortunately adopted is the dot syntax. Any other symbol would have worked, but the dot is just way too easy to overlook. I think it is because it was initially developed for people primarily working with matrices. Most of the things I do is actually based around multidimensional arrays so when I do operations I almost always want element-wise operations. Unfortunate…

Perhaps you should look at D language offering, it has awesome UFCS feature [1] that some other languages are copying now and a REPL.

For multi-dimensional array matrix it provides the fastest computation as well, even compared to Chapel and Julia [2].

[1]https://tour.dlang.org/tour/en/gems/uniform-function-call-sy...

[2]https://dlang.org/blog/2020/06/03/a-look-at-chapel-d-and-jul...

Re: Julia as a CLI Calculator

#124
post #47

I use Mathematica as my advanced calculator. It’s a functional language with an extremely vast and consistent mathematical and non-mathematical library, top notch symbolic capabilities (SymPy is just child’s play in comparison), top notch numerical capabilities, and very decent performance. You certainly don’t need to write your own rotation function — well, 2D rotation is trivial, but what if you want 3D rotation ar…

Mathematica is free on Raspberry Pi, so someone could put together an amazing physical calculator:

- https://www.wolfram.com/raspberry-pi/

- https://blog.wolfram.com/2019/07/11/mathematica-12-available...

Re: Julia as a CLI Calculator

#125

Since this is a calculator topic, I'd like request your input on which calculators you use. I use the Emacs calculator (M-x calc) and XCalc ( http://www.tordivel.no/xcalc/ ) as I like to use RPN calculators. The Windows 10 calculator is painful and slow. XCalc has a mini mode, where it will sit as a small, single line without distracting you too much. I like that feature very much. One thing with Emacs is that I forg…

[deleted]

Re: Julia as a CLI Calculator

#126
post #6

Earlier quoted context omitted.

> Simply loading the REPL takes half a second for me. I juse it all the time as a simple calculator. Half a second is precisely what is meant by "excruciatingly slow". If I need a simple calculator, I expect to be able to use it to compute intermediary results in a shell loop. If my loop has one thousand iterations, you are spending about 10 minutes just initializing the interpreter. This is absurd. Of course, you ca…

> If I need a simple calculator, I expect to be able to use it to compute intermediary results in a shell loop. No offense but that must be one of the dumbest ideas I have heard in a long time. The reason you write something in a shell script is because it is portable on all Unix systems. If you add a dependency to a particular programming language like Julia, then that portability is out the windows. You require ins…

> No offense but that must be one of the dumbest ideas I have heard in a long time.

Thanks. This is not the first time I've been told that.

> The reason you write something in a shell script is because it is portable on all Unix systems.

This is definitely not my case. I write plenty of shell code at work, but rarely distribute it. It is just for arranging data around, preparing one-off experiments, and so on.

> Running a complicated shell script that calls out to Julia 1000 times makes absolutely NO SENSE!

I agree that this may be a rare use case, but it is legitimate nonetheless. Moreover, the best tools are those that can be used successfully in ways that the creator of the tool would find abhorrent.

> It is a completely contrived example with no practical application.

This was a concrete example actually. I had a shell script that cropped, denoised and registered a collection of a few thousand photos scattered in a directory tree. It was a four-line pipeline that called a few command line tools from imagemagick and gmic to do the image processing work. At one point, I realized that I had to apply an homography to the images (given by a 3x3 matrix that was stored as 9 numbers in a text file) to map them to a different coordinate system. This involved a 3x3 matrix multiplication for each image. I did this multiplication in julia, my favorite calculator. The running time of the whole thing went from 10 to 20 minutes. Doing the "correct" thing and rewriting everything in julia would be extremely painful.

> Besides when people say "calculator," I think most reasonable people assume an interactive system for doing calculations

When you say "CLI Calculator", you can also think about a calculator that you can call from your shell command line. This is the case for example for the classical calculators bc(1) and dc(1), which are non-interactive, and purposefully intended to be called inside loops in a shell script.

Re: Julia as a CLI Calculator

#127

Earlier quoted context omitted.

> If I need a simple calculator, I expect to be able to use it to compute intermediary results in a shell loop. No offense but that must be one of the dumbest ideas I have heard in a long time. The reason you write something in a shell script is because it is portable on all Unix systems. If you add a dependency to a particular programming language like Julia, then that portability is out the windows. You require ins…

> No offense but that must be one of the dumbest ideas I have heard in a long time. Thanks. This is not the first time I've been told that. > The reason you write something in a shell script is because it is portable on all Unix systems. This is definitely not my case. I write plenty of shell code at work, but rarely distribute it. It is just for arranging data around, preparing one-off experiments, and so on. > Runn…

> Doing the "correct" thing and rewriting everything in julia would be extremely painful.

Not necessarily: https://docs.julialang.org/en/v1/manual/running-external-pro...

Re: Julia as a CLI Calculator

#128

Earlier quoted context omitted.

> No offense but that must be one of the dumbest ideas I have heard in a long time. Thanks. This is not the first time I've been told that. > The reason you write something in a shell script is because it is portable on all Unix systems. This is definitely not my case. I write plenty of shell code at work, but rarely distribute it. It is just for arranging data around, preparing one-off experiments, and so on. > Runn…

> Doing the "correct" thing and rewriting everything in julia would be extremely painful. Not necessarily: https://docs.julialang.org/en/v1/manual/running-external-pro...

That's great! I didn't know about that

Re: Julia as a CLI Calculator

#129

One of my main gripes about matlab and that Julia unfortunately adopted is the dot syntax. Any other symbol would have worked, but the dot is just way too easy to overlook. I think it is because it was initially developed for people primarily working with matrices. Most of the things I do is actually based around multidimensional arrays so when I do operations I almost always want element-wise operations. Unfortunate…

You can use the @. macro to dot an entire block. I personally like the dot syntax. It's ergonomic, and provides cool stuff like this: https://julialang.org/blog/2017/01/moredots/ I don't know of an equivalent functionality in any other language.

The @. syntax is definetly an improvement. I don't have an issue with the principle of the dot syntax just with the symbol. The examples in your link perfectly illustrate the issue. If this was a line in a long code base maybe even with mixed element-wise and matrix operations it would be very easy to overlook a missing dot. It would be even worse if the constants were floats. It is just such a terrible choice of symbol for this operation, because it is so easy to overlook.

Everyone I know always looks for missing dots if they encounter a some nonstraight forward bug in matlab (I don't know any Julia users).

Re: Julia as a CLI Calculator

#130

Earlier quoted context omitted.

no it's not, because a key part of OO is encapsulation. You really do need a functional language with naked, fully introspectable types everywhere, for this to work effectively.

I tried it in Dart and it worked, so it's possible. But maybe I don't understand your point, if so, tell me what exactly would be impossible to implement in a language like Swift, Dart, Kotlin.

yes, you can add an inspect method to every object, but you'll also have to add an inspect method to every object. That's the problem.
Post reply on HN