JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.57k stars 5.47k forks source link

support for practical Ruby/Perl-like one-liners #20293

Open abhi18av opened 7 years ago

abhi18av commented 7 years ago

Hi @julia-lang team

I've been following the evolution of julia language for a while now and I am trying to incorporate it into my daily work-flow which does involve a lot of one liners lately. The one that I mostly use is the cloud based juliabox

juser@juliabox:~$ julia -v                                                                                                                                   
julia version 0.5.0                                                                                                                                          

So, my question is are there any plans to add the ruby like command line flags as listed below. I know that this might be a low-priority thing but still, julia has a tendency to spoil the user for wanting more :+1:

Usage: ruby [switches] [--] [programfile] [arguments]                                                                                                        
  -0[octal]       specify record separator (\0, if no argument)                                                                                              
  -a              autosplit mode with -n or -p (splits $_ into $F)                                                                                           
  -c              check syntax only                                                                                                                          
  -Cdirectory     cd to directory, before executing your script                                                                                     
  -Fpattern       split() pattern for autosplit (-a)                                                                                                         
  -i[extension]   edit ARGV files in place (make backup if extension supplied)                                                                             
  -l              enable line ending processing                                                                                                              
  -n              assume 'while gets(); ... end' loop around your script                                                                                     
  -p              assume loop like -n but print line also like sed                                                                                           
  -rlibrary       require the library, before executing your script                                                                                          
  -s              enable some switch parsing for switches after script name                                                                                  
  -S              look for the script using PATH environment variable                                                                                                                                                       
tkelman commented 7 years ago

Generally we prefer implementing most things in the language rather than as command line flags. That way they're usable by applications that embed julia, and they can be toggled interactively in a repl or ijulia session, or for specific sections of code.

abhi18av commented 7 years ago

Oh, right)

Btw, you've made me curious - could you point me to an application where Julia has been successfully embedded?

tkelman commented 7 years ago

That's a better question for discourse.julialang.org. node-julia is one public example that comes to mind.

tknopp commented 7 years ago

http://docs.julialang.org/en/stable/manual/embedding/

abhi18av commented 7 years ago

@tknopp , yes I do know about the docs but I'm looking more along the lines of node-julia as @tkelman suggested - thanks.

So, correct me if I'm wrong. Julia is as embeddable as GnuGuile ?

tkelman commented 7 years ago

The Julia standard library has way more dynamic-library dependencies than Guile (the majority of which are technically optional, but it isn't currently very easy to remove some of them). Otherwise I don't know if anyone here is familiar enough with Guile to meaningfully answer that question, and again it's better for discourse.

abhi18av commented 7 years ago

Oh, I see. Thanks @tkelman and @tknopp

StefanKarpinski commented 7 years ago

I do really like Perl's command-line switches for this sort of thing and still regularly use them to write Perl one-liners (Ruby's were largely borrowed from Perl). We could have some macros that implement some of the functionality to allow one-liners and then provide a way to invoke julia which makes those macros available. I'm imagining something like this:

julia -1 '@ple replace(_, r"[aeiou]+", "_")'

Here the -1 would stand for "one-liner", which would make the @ple macro available (along with various other handy macros). I think we could leave this issue open for some discussion of what hooks and other work are necessary to make this practical. One of our major practical issues is that startup time, although much better than it once was, is still a bit long.

tkelman commented 7 years ago

would be better to have a oneliner.jl entry point that does whatever setup and loading you need. you could alias that to a shorter name in your shell if you want. I'm skeptical any of this needs command line flags, we should be moving the ones we have like depwarn into the language instead.

StefanKarpinski commented 7 years ago

The whole point of one-liners is that it should be a ready tool that you don't need to do very much to use – ideally, just a few characters. If we're going to do it that way, we need, at the very least a mechanism for concisely loading packages in specific like the proposed oneline.jl. If we have to write this:

julia -e 'using OneLiner; @ple replace(_, r"[aeiou]+", "_")'

That's not the most verbose thing in the world, but it's enough a pain for one-liners that people won't use it – or at least I won't. At some point it will get embarrassing that I still write my one-liners in Perl.

tkelman commented 7 years ago

There are packages that define command-line entry points. This doesn't need to be implemented in C here to have a convenient UI.

abhi18av commented 7 years ago

@StefanKarpinski I like where this is going - thanks for thinking "inside the quotes" 👍

StefanKarpinski commented 7 years ago

Who said anything about implemented in C?

tkelman commented 7 years ago

all of the command line argument parsing for the julia executable is in libjulia

StefanKarpinski commented 7 years ago

And I changed the scope of the issue to being "provide some mechanism to support one-liners."