I am new to mac, and am in the process of getting my computer setup with all the programs I need, one of them being Haskell.
To my surprise, the Haskell platform for OS X is not like in Windows (where there is an GUI editor built on the platform installation - winGHiC). After looking a lot around, I found this editor TextMate which is supposed to be compatible with Haskell but am finding it quite complex to setup the Haskell Bundle for it.
I have already downloaded and installed the following:
Haskell Platform for Mac OS X
Xcode 3.4 (Haskell Prerequisite)
TextMate
haskell.tmbundle files (mentioned above)
Is anyone familiar on how to get it working? It will mean a lot to me a detailed stepwise explanation, like I said, I has been only 1 day since I used OS X for the first time.
Thanks a bunch.
Well it's good work that you have found that the tmbundle is on Github these days.
You should be able to find the inbuilt options by clicking Bundles, then Haskell. There are fairly few in the standard Haskell.tmbundle. The most obviously useful one is ... load file command-shift-r or command-R. If you have written a module with ending .hs or .lhs, it ... opens it in ghci.
(There was some talk of an integrated terminal in TextMate II, but who knows? One annoying feature of a non-integrated terminal is that one is tempted to 'reload' by clicking command-R rather than by doing :r inside ghci; in certain frenzies it will develop that I have 15 copies of Terminal open.)
Many of the nice features are just general TextMate things, determined by the language description, so it might be good to read a general description of TextMate niceties. For example, if several lines are highlighed, then command-/ comments them out with --s; or, if they are already commented, uncomments them. I had hacked together something to do this, long before I realized it was already there, not having studied the manual closely enough.
Everything has keybindings, of course, and it is very easy to add your own to run little scripts and insert little snippets, much more so than in Emacs, say.
Under Bundles click Bundle Editor and examine the text for different kinds of things.
So, for example, to make a tab trigger to start a language extension pragma {-#LANGUAGE ... #-} where the cursor is in the space ...make a copy of a Snippet and substitute
{-#LANGUAGE ${1}#-}
selecting Activation: Tab Trigger, and (say) LANG as the trigger.
One nice thing is that they are all shell scripts, or else (like this one) partial shell scripts with some TextMate variables around, and you can pretty much write them in your own preferred language. (For the Haskell bundle I don't have any Haskell ones to speak of any more, but for other bundles I do.)
The syntax highlighting is surprisingly sound, but trips over a few fancy extensions, e.g. "PackageImports" , GADT syntax, markup for the Haddock documentation system, and some other oddities. I have hacked my own, but I find the format of the syntax files pretty unintelligible, so it's no use sending you a copy. The Haskell.tmbundle has been emended by some knowledgeable Haskellers in the last two or three years. The person who first made it was just learning Haskell, and hadn't e.g. composed Haddocked modules, but on the other hand, he seems fortunately to have been very skilled and to have had an intimate knowledge of the TextMate machinery.
Notice by the way that TextMate stores the emendations you make in the Bundle Editor in a rather strange way. The bundles that come with TextMate, e.g. C, Ruby, HTML, LaTeX, etc. are in /Applications/Textmate.app/.../Bundles. The ones you install are in /Library/Application\ Support/TextMate/Bundles. When you make emendations through the Bundle Editor, they are stored in your local ~/Library/Application\ Support/TextMate/Bundles. It sort of makes sense but it's a little complicated, and impedes public improvement of the Haskell bundle. (The one bundle I share with people, not the Haskell one, I keep in the lattermost, outermost directory under git revision, so the original and my emendations are together.)
The "Lookup on Hoogle" keybinding/option acts on highlighted terms; here's a replica for the hayoo website, which can search for uses of a type-signature
echo "<meta http-equiv=\"refresh\" content=\"0;
http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}\">"
If you cabal install hoogle, then you can make a local call to hoogle with a script like so:
hoogle --w --n=100 '${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}'
choosing Save: Nothing, Input: Selected Text, Or: Word, Output: Show as HTML
Other emendations I have made are mostly trivial, like a tab trigger snippet for `{-#LANGUAGE ... #-} or else eccentricities of my own.
One thing worth mentioning that I managed to integrate is the typeof executable from Hackage, cabal install typeof, which runs to ghci for an inferred type signature. I have a key binding to show the inferred type as displayed bit of html, but also to insert it. It's a bit delicate but here is the text for the displayer of types
#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module
choosing Input: Selected Text, Or: Line ; Output: Show as Tool Tip, Activation : Key Equivalent (then choose a keybinding , mine is control-option-command-j) Similarly, for type insertion via typeof make a new C (command file) heading and include this:
#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module | typeof_wordorder
# typeof_wordorder is the following hack compiled
# in my local ~/bin
# module Main where
# main = interact reword where
# reword :: String -> String
# reword xs =
# xs ++ (head . words . concat . lines $ xs)
Here typeof and typeof_worderorder are Haskell executables, the first cabal-installed, the second is the above commented idiocy, compiled in my local ~\bin to get around some escaping nonsense. Here you should choose Output : Insert as Snippet
Sorry, I'm just thinking of random things. You should keep posting questions under this heading, as I think it would be worthwhile to see how one might trip up, but also what hacks our cleverer Haskeller friends may have thought of. I keep meaning to put a 'fork' of my tmbundle on github, but it's not too thrilling, and the organization of Bundle directories forever defeats me.
Related
I want to add some additional syntax highlighting definitions to an existing bundle, but I need some general advice on how to do this. I'm not building a syntax from scratch, and I think my request is pretty simple, but I think it involves some subtleties for which I find the manual somewhat impenetrable in finding the answer.
Basically, I'm trying to fill out the syntax definitions for the Stata bundle. It's great, but there is no built in support for automatically highlighting the base commands and the installed functions, only a handful of basic control statements. Stata is a language which is primarily used by calling lots of different high level pre-defined command calls, like command foo bar, options(). The convention is that these command calls be highlighted.
There are a ton of these commands, and stubs which are used for convenience. Just the base install has almost 3500. Even optimizing them using the bundle helper, which obviously gets rid of the stub issue, still yields a massive regex list. I can easily cut this down to less than 1000 important ones, but its still a lot. There are also 350 "functions" which I would like to match with the syntax function()
I essentially have 3 questions:
Am I creating a serious problem by including a very comprehensive list of matching definitions?
How do I restrict a command to only highlight when it either begins a line or there is only whitespace between the beginning line and the command
What is the preferred way of restricting the list of functions() to only highlight when they have attached parentheses?
Vimscript is difficult. Ruby is not quite so diffiuclt. Customizing Vim with Ruby scripts can be done, and I am trying to learn how. This is a useful presentation about it which covers the basics, but meaningful examples are scarce (and these are rather complicated), so I'm wondering if anyone with experience in this area can offer some smaller examples of Vim mappings and shortcuts written in Ruby.
As a specific example of the kind of scale I'm looking for, let's suppose I want to create section headers for my documentation or something, as in
----------------------------------------------
------------------- SECTION ------------------
----------------------------------------------
where the section name is centered in the set of hyphens, and to achieve this I visually select the word
SECTION
on it's own line, and hit leader <arbitrary keystroke>.
Counterargument: Vimscript isn't difficult, maybe a bit different; after all, much of it is modeled after Python.
I do agree that for certain, complex tasks (especially anything that requires interaction with the "outside world", be it file systems, web service calls, etc.), or stuff that benefits from library functions, a different programming language (and fortunately one can choose among powerhorses like Perl, Python, and Ruby) has undeniable benefits.
But the example task you're giving is just a simple sequence of yanking, simple string manipulation, followed by paste. There's little meat, and the interaction with the Vim buffer isn't that different when done in an integration language. That's my main point: You still have to integrate with Vim, and for that, some knowledge of Vim's structure (and that means Vimscript) is necessary.
so this week consisted of me installing Logtalk, one of the extensions for Prolog. In this case I'm using Prolog SWI, and I've run into a little snag. I'm not sure how to actually consult my own projects using Logtalk. I have taken a look at the examples that Logtalk comes with in order to understand the code itself, and in doing so I've been able to load them and execute them perfectly. What I don't understand though is what is actually going on when logtalk is loading a file, and how I can load my own projects.
I'll take the "hello_world" example as the point of discussion. The file called hello_world, is located in the examples folder of the Logtalk files. and yet it is consulted like so:
| ?- logtalk_load(hello_world(loader)).
First thing I thought was "that is a functor", looking at what it was doing using trace, I found that it was being called from the library and was being told how to get to the examples folder, where it then opened the "hello_world" folder and then the "loader" file. After which normal compiling happened.
I took a look at the library and couldn't figure out what was going on. I also thought that this can't possibly be the practical route to load user created projects in Logtalk. There was another post that was asking how to do this with SWI as well, but it didn't have any replies and didn't look like any effort had been made to figure the problem out.
Now let me be clear on something, I can use the "consult('...')." command just fine, I can even use "consult" to open my projects, however if I do this the logtalk console doesn't seem to be using any of the logtalk extensions and so is just vanilla prolog. I've used an installer for windows to install logtalk and I know that it is working as I've been looking at the examples that it comes with.
I've tried to find a tutorial but it is very difficult to find much of anything for Logtalk, the most I have found is this documentation on loading from within your project:
logtalk_load/1.
logtalk_load/2.
which I understand like so:
logtalk_load(file). % Top level loading
logtalk_load(folder(file). % Bottom level loading
So to save a huge manual load each time I would have a loader file that will load the other components of my project (which is what the examples for Logtalk do). This bit makes sense to me, I think, how I get to my loader file, doesn't.
Whether or not I have been understanding it correctly or not remains to be seen, but even if I have been understanding it correctly, I'm still lost as to how I load my own projects. Thanks for any help you can give, if you could give an example that'll be best as I do learn from examples quite quickly.
LITTLE UPDATE
You asked if I was using a logtalk console for my program running, and I am, I'm using the one that is provided and referred to during the "QUICK_START" file [Start > Programs > Logtalk > "Logtalk - Prolog-SWI (console)"] I thought to double check if the logtalk add ons were working and tested the "birds" example since it uses objects and is a nice familiar example. Yet again, everything works fine when using the logtalk_load/2 functor.
I took a look at what the library path was referring to a bit more given the feedback given so far. Looking into how logtalk loads files. Set up as it is so far, without changing things logtalk consults a folder which contains a prolog file called libpaths. It is basically how the examples are found, all it is is a part way description for where to get a file from. So when I say "logtalk_load/2" from what I can tell at least I'm going to this file and finding where the folder is that I'm asking for.
Now since I have already placed my own project folder in the examples folder, I promptly added my own folder to the list to test if this would at least be a part way solution to help me understand things a bit more. I added the following to the libpaths.pl file.
logtalk_library_path(my_project, examples('my_project/')).
% The path must end in a / so I have done so
So, I've got my folder path declared, got my folder, and the loader file is what I'll be calling when I use the loader. Without thinking about setting my own lib path folder, I should have enough to get things working and do some practical learning. But alas no, seems my investigation failed and I was returned the following:
ERROR: Unhandled exception: existence_error(library,project_aim)
Not what I wanted to see, I'm back to this library error business. I'm missing a reference to my project folder somewhere but I don't know where else it could need referencing. Running trace on the matter didn't help I simply had the following occur:
Call: (17) logtalk_library_path(my_project, _G943) ? creep
Fail: (17) logtalk_library_path(my_project, _G943) ? creep
ERROR: Unhandled exception: existence_error(library,my_project)
The call is failing, I'm simply not finding a reference where ever it is logtalk is looking. And I'm a novice at best when it comes to these sorts of issues, I've been using computers now for only 3 years and programming for the past 2 in visual studios using c# and c++. At least I've shone some more light on the matter, any more helpful advice given this information?
Please use the official Logtalk support channels for help in the future. You will get timely replies there. Daniel, thanks for providing help to this user.
I assume that you're using Logtalk 2.x. Note that Logtalk 3.x supports relative and full source file paths. In Logtalk 2.x, the logtalk_compile/1-2 (compile to disk) and logtalk_load/1-2 (compile and load into memory) predicates take either the name of a source file (without the .lgt extension) OR the location of the source file to be loaded using "library notation". To use the former you need first to change the current working directory to the directory containing the file. This makes the second option more flexible. As you mention, the hello_world example you cite, can be loaded by typing:
?- logtalk_load(hello_world(loader)).
or:
?- {hello_world(loader)}.
Logtalk 2.x and 3.x also provide integration with some SWI-Prolog features such as consult/1, make/0, edit/0-1, the graphical tracer and the graphical profiler. For example:
?- [hello_world(loader)].
********** Hello World! **********
% [ /Users/pmoura/logtalk/examples/hello_world/hello_world.lgt loaded ]
% [ /Users/pmoura/logtalk/examples/hello_world/loader.lgt loaded ]
% (0 warnings)
true.
To load your own examples and projects, the easiest way is to add a library path to the directory holding your files to the $LOGTALKUSER/settings.lgt file (%LOGTALKUSER%\settings.lgt on Windows) as Daniel explained. The location of the Logtalk user directory is defined by you when using the provided installer. The default is My Documents\Logtalk in Windows. Editing the libpaths.pl file is not a good idea. Use the settings.lgt file preferentially to define your own library paths. Assuming, as it seems to be your case, that you have created a %LOGTALKUSER%\examples\project_aim directory, add the following lines to your %LOGTALKUSER%\settings.lgt file:
:- multifile(logtalk_library_path/2).
:- dynamic(logtalk_library_path/2).
logtalk_library_path(project_aim, examples('project_aim/').
If you have a %LOGTALKUSER%\examples\project_aim\loader.lgt file, you can then load it by typing:
?- {project_aim(loader)}.
Hope this helps.
What makes me uncertain of my answer is just that you claim the usual consult works but not logtalk_load. You do have to run a different program to get to Logtalk than Prolog. In Unix it would be something like swilgt for SWI-Prolog or gplgt for GNU Prolog. I don't have Windows so I can't really tell you what you need to do there, other than maybe make sure you're running a binary named Logtalk and not simply Prolog.
Otherwise I think your basic problem is that in Windows it's hard to control your working directory. In a Unix environment, you'd navigate your terminal over to the directory with your files in it and launch Logtalk or Prolog from there. Then when you name your files they would be in the current directory, so Prolog would have no trouble finding them. If you're running a command-line Prolog, you can probably configure the menu item so that it will do this for you, but you have to know where you want to send it.
You can use the functor notation either to get at subdirectories (so, e.g., foo(bar(baz(bat(afile)))) finds foo\bar\baz\bat\afile.lgt). This you seemed to have figured out, and I can at least corroborate it. This will search in its predefined list of functors, and also in the current directory. But you could launch Logtalk from anywhere and then run, say, assertz(logtalk_library_path(foo, 'C:\foo\bar\baz\bat')). after which logtalk_load(foo(afile)) is going to be expanded to C:\foo\bar\baz\bat\afile.lgt.
Building on that technique, you could put your files in the Logtalk user directory and use $LOGTALKUSER as demonstrated in the documentation. I can't find a definitive reference on where the Logtalk user directory will be on Windows, but I would expect it to be in the Documents and Settings folder for your user. So you could put stuff in there and reference it by defining a new logtalk_library_path like this.
It's nice, but it still leaves you high and dry if you have to keep on re-entering these assertions every time you launch. Fortunately, there is a Logtalk settings file named settings.lgt in your Logtalk user directory which has a chunk of commented-out code near the top:
% To define a "library" path for your projects, edit and uncomment the
% following lines (the library path must end with a slash character):
/*
:- multifile(logtalk_library_path/2).
:- dynamic(logtalk_library_path/2).
logtalk_library_path(my_project, '$HOME/my_project/').
logtalk_library_path(my_project_examples, my_project('examples/')).
*/
You can simply uncomment those lines and insert your own stuff to get a persistent shortcut.
You can also write a plrc file for SWI Prolog to define other things to happen at startup. The other option seems cleaner since it's Logtalk-specific, but a plrc is more general.
Once you have that machinery in place, having a loader file will be a lot more helpful.
NOTE: I don't have Windows to test any of this stuff on, so you may need to make either or both of the following changes to the preceeding:
You may need to use / instead of \ in your paths (or maybe either will work, who knows?). I'd probably try / first because that's how all other systems work.
You may need to use %LOGTALKUSER% instead of $LOGTALKUSER, depending on how Logtalk expands variables.
Hope this helps and I hope you stick with Logtalk, it could use some passionate users like yourself!
I often use Sweave to produce LaTeX documents where certain chunks are produced dynamically by executing R code. This works well - but is it also possible to have code chunks that are executed in different ways, e.g. by executing the code in the shell, or by running Perl, and so on? It would be helpful to be able to mix things up, so I could do things like run some shell commands to fetch some data, run some perl commands to pre-process it, and then run R commands to analyze it.
Of course I could use all R chunks and use system() as a poor-man's substitute, but that doesn't make for very pleasant reading in the document.
The new new thing (for multi-language, multi-format) docs may be dexy.it which for example these guys at opengamma.org use as the backend.
Ana, who is behind dexy, is also giving a lot of talks about it so also look at the dexy blog.
It's not directly related to Sweave, but org-babel, which is part of Emacs org-mode, allows to mix code chunks of different languages in one file, pass data from one chunk to another, execute them, and generate LaTeX or HTML export from the output.
You can find more informations about org-mode here :
http://www.orgmode.org/
And to see how org-babel works :
http://orgmode.org/worg/org-contrib/babel/
There is certainly no easy way to do this other than through either foreign language interfaces from R (maybe through inline if it's supported), or system(). For what it's worth, I would just use system(); that should be easy enough.
You can see this previous question about having a Sweave equivalent for Python, where one of the respondents actually creates a separate interface. This can give you a sense what what it would take to embed other languages which may not already be supported. At a minimum, you have to do major hacking on the Sweave driver.
Do you know emacs" org-mode and, more specifically, Babel? If you already know Emacs or are willing to switch to Emacs, then org-mode and Babel are the answer to your question(s).
For instance, I am currently working on a document which contains some shell-scripts, does computations with R and creates flow charts with dot (graphviz). Org-mode can export a variety of formats, e.g. LaTeX (that's what I use).
There is the StatWeave project which uses java rather than R to do the weaving, but will run multiple programs instead of just R. I don't know how hard it would be to get it to do Perl or other programs like that, but the homepage indicates that it already works with R, SAS, Stata, and others:
http://www.cs.uiowa.edu/~rlenth/StatWeave/
I'm really used to auto-completion coming from Netbeans.
In Netbeans, when I type a 'string' and then hit a 'dot' it will print out a list of methods for the String class.
TextMate doesn't seem to have that function.
Is it something you could add?
Would save A LOT of time instead of using the ri/irb/online doc all the time.
Install the Ruby TextMate bundle, open a Ruby file and type alt+esc to get the autocompletion.
You have discovered the fundamental difference between a text editor and an IDE: a text editor edits text (duh!), i.e. an unstructured stream of characters. It doesn't know anything about objects, messages, methods, mixins, modules, classes, namespaces, types, strings, arrays, hashes, numbers, literals etc. This is great, because it means that you can edit anything with a text editor, but it also means that editing any particular thing is harder than it were with a specialized editor.
A Ruby IDE edits Ruby programs, i.e. a highly structured semantic graph of objects, methods, classes etc. This is great, because the IDE knows about the rules that make up legal Ruby programs and thus will e.g. make it impossible for you to write illegal Ruby programs and it can offer you automated transformations that guarantee that if you start out with a legal Ruby program, you end up with a legal Ruby program (e.g. automated refactorings). But it also means that you can only edit Ruby programs.
In short: it's simply impossible to do what you ask with a text editor. You need an IDE. (Note: you can of course build an IDE on top of a text editor. Emacs is a good example of this. But from what I have read, the TextMate plugin API is simply not powerful enough to do this. I could be wrong, though – since I don't have a Mac, I'm mostly dependent on hearsay.)
TM's "equivalent" is hitting escape, I believe.
You can make escape "go across files" for completion if you use the ruby amp TM bundle http://code.google.com/p/ruby-amp/
GL.
-r