Julia: support for practical Ruby/Perl-like one-liners

Created on 28 Jan 2017  路  15Comments  路  Source: JuliaLang/julia

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                                                                                                                                                       

Most helpful comment

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 鈥撀爄deally, 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 鈥撀爋r at least I won't. At some point it will get embarrassing that I still write my one-liners in Perl.

All 15 comments

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.

Oh, right)

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

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

@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 ?

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.

Oh, I see. Thanks @tkelman and @tknopp

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.

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.

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 鈥撀爄deally, 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 鈥撀爋r at least I won't. At some point it will get embarrassing that I still write my one-liners in Perl.

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

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

Who said anything about implemented in C?

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omus picture omus  路  3Comments

StefanKarpinski picture StefanKarpinski  路  3Comments

wilburtownsend picture wilburtownsend  路  3Comments

tkoolen picture tkoolen  路  3Comments

helgee picture helgee  路  3Comments