Interpreting F# files with Mono - macos

After installing F# on OS X with Homebrew, In Haskell (with GHC), it's possible run code on an interpreter. I was wondering if there is a way to run files without compiling them first in F#? Maybe with fsharpi?
Just to clarify, I do not mean the REPL itself, but running an app without intermediary files.

You can use fsharpi which is an interactive mode for F#. You can just start fsharpi and then type F# code in the console that starts:
> 1 + 1;;
val it : int = 2
You can also write your code in a fsx file and pass it to fsharpi to have it executed. Say you have demo.fsx with:
printfn "Hello world"
You can then run fsharpi demo.fsx and it should print hello world for you!
Some people use F# from command line in this way, but it gets more productive if you setup your favorite editor to use F# - then you can type code directly in the editor and send it to F# Interactive using some command. There are good plugins for Atom, Emacs, vim, Sublime and others - see the links here.
PS: It is worth adding that F# Interactive does not actually interpret the code. It compiles it on the fly and runs it, so it has the same performance profile as compiling the code in the usual way.

Related

Making an Application for the Linux command line

I've been trying to make a package for the Linux command line. I have a few questions that will probably seem silly to those of you seasoned developers out there, but the documentation and guides online have been unclear to say the least.
I'm actually a developer myself and have been for the past several years but have never dipped my toe into making applications/packages for the Linux terminal, but I now have to do it for work. I would prefer to do it in C# or Python if possible, but the only thing that I've been able to get working is Bash scripts. There's no initialization or template I could find online for making one of these Linux Terminal packages. I might be bad at googling, but after three hours, I've concluded that there just some sort of secret society that exclusively knows how to make these.
I'm fine with using Bash if I can't make terminal apps/packages in other languages, but it's still a bit annoying. For example, I can't run a file without ".sh" at the end. If I run my app, test.sh, I simply type test.sh [args] but if I run another package, such as cat, I can just use cat filename without having to type cat.sh filename.
In short,
1) Do I have to use Bash?
2) If so, how can I run scripts without the ".sh" extension?
3) If not, how can I make terminal apps with C#, Python, etc.? Is there some kind of template to get you started?
Thanks for your time.
1) Do I have to use Bash (to make applications/packages for the Linux terminal)?
No, you can program in any programming language installed in your machine.
2) If so, how can I run scripts without the ".sh" extension?
The .sh extension is a convention for Bash scripts, not a requirement. You can use any extension. Suppose my_script, my_script.sh and my_script.bash have the same contents, then these commands are equivalent:
$ bash my_script.sh
$ bash my_script.bash
$ bash my_script
You could also make the script executable with chmod +x my_script.sh and run it as ./my_script.sh
3) If not, how can I make terminal apps with C#, Python, etc.? Is there some kind of template to get you started?
To run programs in a given language, you have to install the language first. Installation is typically done with a package manager. Alternatively you could download the language source code and build it. Then you can create programs with that language. This is a sample Python script and its output:
$ cat my_script.py
#!/usr/bin/env python
print "test"
$ ./my_script.py
test

Rubyinstaller for Windows - ruby does nothing

I've tried using Ruby 2.0 x64 and Ruby 1.9.3 for Windows using RubyInstaller. Entering ruby -v works as expected, and running gem gives me the expected usage docs. Running and using the Interactive Ruby application works as expected. I am running Windows 8.1 Update.
However, for both installations, running ruby from cmd gives me a blank prompt where I can type, but nothing is executed when I press enter. If I attempt to install a gem, there is a similar issue where the program is running, but there is absolutely no output, and nothing happens.
I can't seem to be able to find a similar issue elsewhere. Does anyone know what might be wrong, and how I could fix it?
What did you expect to happen? ruby.exe is the ruby interpreter, meant for running ruby scripts. Normally, to use it you would create a file containing valid ruby commands with your favorite text editor (but not a word processor). If you save the file as foobar.rb, typing ruby foobar.rb (or if you told the installer to associate .rb files with ruby, typing just foobar.rb) will execute the commands in the file as a script/program. If you don't supply a script file name, ruby goes into input mode and expects you to type in a program on the spot. It won't give any feedback until you indicate end-of-file by typing CTRL-z, at which point it will process what you typed and most likely tell you about all the errors you made. If you want line-by-line interactive feedback, use irb.

IPython jump to error in vi / Vim?

When using Vim to develop C code, it's possible to run :make then :cp to jump directly to compiler errors in the code.
I wonder if there is any similar functionality when using IPython with Vim as the editor, so that when an error occurs I can type something that starts the editor, opens the file, and goes directly to the line?
It should be possible for syntax errors, but I don't know if the code to do that still works - it's been around for some time without any tests. To try it, set this in your ipython_config.py file:
c.TerminalInteractiveShell.autoedit_syntax = True

How to use a text file as standard input to test my program in XCode 4.33

I'm having trouble figuring out how to test my program using XCode. I usually edit in the command line with vim, but am trying to transition to an IDE. I'm sure there is an easy way to do the equivalent of homework.out < testfile.txt
Thanks!
I haven't tested it, but putting "< testfile.txt" in the scheme's command line arguments may work. Apparently doing something similar worked for an earlier version of Xcode.

How to write ruby code easier?(I mean in terminal write and then run it)

When I write a little ruby code, after a little bit, I always need to create a new terminal tab to ruby it, to see if it's correct.
Are there any ways to do it in one window? Like a vim plugin or some other tool?
The following should work in vim, after you've saved the file:
:!ruby %
Or even
:!%
This works under Linux when you have the correct "shebang" as the first line of the ruby file:
#!/usr/bin/env ruby
For extra fun, you can map this to a key in your ~/.vimrc:
map <F8> :!ruby %<CR>
Do you mean you need an interpreter to see what your code does? If so, check out irb.
The way you should check if your code works is using unit tests, not running it in the console or irb. Indeed, irb is a good solution for small fragment of code or to check for specific statements.
However, there are some solutions to your specific question.
You can write the code in a file, save it and run it from the console.
ruby filename.rb
If you use TextMate, you can press ⌘ + R to execute the current code
Do as Simone Carletti said.
And for editing and saving your file suggest you Scite.
http://www.scintilla.org/SciTEDownload.html here you can download it for many different operating systems.
You get syntax highlighting in a very lightweight editor for almost everything (html, ruby, eruby, xml,...).
But you will need to have at least a Window Manager running.
in ~/.vimrc
autocmd FileType ruby imap <F8> <C-o>:w <CR> <C-o> :!ruby % <CR>
this way you can save and execute your file at once within insertion mode
In vim:
:!ruby %
will execute ruby on the current file. Remember to save it first!
If you are the Emacs type you should check out ruby-mode (which IIRC was written by Matz) and inf-ruby. See e.g. http://lathi.net/pages/emacs-ruby
You don't say what OS you're using, so I'm assuming either Linux or Mac-OS.
When you're at a command-line and using vim (not gvim) you can do a <CNTRL>+Z to temporarily halt the editor and return to the command-line. Issue any commands you need, then use "fg" to return to the editor.
There are times I'll use :!ruby % from inside vim (or gvim) but sometimes I need the real command line and if I'm ssh'd into a machine the <CNTRL>+Z trick is nice.
Agreed with #Simone Carletti. If you are learning the language and want to make sure that methods/classes are doing what you want then you can use irb.
There is a gem called interactive_editor which enable you to run vim inside irb (side-by-side actually). Watch this Vimcast for demo.

Resources