<tantris>
thanks! one other small question would be, I often have one shell in which I edit an ocaml file and another one in which I run the ocaml toplevel and paste parts from the file to verify the syntax and to execute it
<tantris>
but when the file gets bigger it gets awkward to paste its contents into the toplevel, is there a way I could read the file from disk? I tried #load but that only seems to load .cma files and open only searched the standard lib path?
<steele>
there is #use, i guess most people use one of the emacs modes
<taw>
yeah
<taw>
tuareg is the way to go
<taw>
try tuareg + vigor if you are a vi fanatic ^^
<tantris>
well I use xemacs for editing files but never did more with it, maybe someone can give me some initial hints?
<taw>
just M-x tuareg-mode
<taw>
nd check the menu that will appear
<taw>
i think tuareg is in standard distribution of xemacs nowadays
<taw>
but i'm not 100% positive about that
<tantris>
hmm "no match" :(
<tantris>
I'll see if my distribution provides it
<Nutssh>
I generally compile and run it non-interactively.
<taw>
$ apt-cache search tuareg
<taw>
tuareg-mode - An emacs-mode for ocaml programs
<tantris>
hmm there is a gentoo ebuld for tuareg-mode but it wants to install emacs also
<taw>
Nutssh: it's takes some time to get used to all the available tools, but this is very good investment and will return with the next project
<taw>
which emacs ?
<tantris>
app-editors/emacs-21.3-r2
<taw>
gentoo is really good at downloading sources for 100x more than you need ^^
<taw>
want libmysql in your application ? download whole mysqld ^^
<taw>
that seems to the philosophy of gentoo
<Nutssh>
I've never gotten to understand how to do it interactively like that I should. BTW, how do I disable the middle-button-click in ocaml-types? I can't paste anymore!
<tantris>
hmm would xemac pick up the emacs tuareg-mode files?
<taw>
i used in with gnu emacs on windoze and xemacs on debian, works fine with either
<Nutssh>
It works with both.
<taw>
most modes work with both fine
<karryall>
Nutssh: I changed the button click to third mouse button in caml.el
<tantris>
well I guess I search for it on the web, 20mb of emacs looks a little bit like a waste
<Nutssh>
The origional file, or a in your homdir?
<karryall>
tantris: there's the regular caml mode, distributed with ocaml which is just fine
<taw>
why does that original caml mode exist ?
<taw>
isn't tuareg enough ?
<karryall>
why does tuareg exist
<karryall>
isn't caml-mode enough ?
<karryall>
Nutssh: the installed caml.el in site-lisp
<Nutssh>
Ok.
<taw>
sure, the question is - why are there two
<tantris>
ohh I just found the app-xemacs/ocaml package
<tantris>
probably thats what I am looking for
anpanman has quit [Read error: 110 (Connection timed out)]
blueshoe has quit [Read error: 104 (Connection reset by peer)]
mattam has quit [Read error: 110 (Connection timed out)]
<tantris>
hmm I now started caml-mode in xemacs, but what is so special about it? I might not get the trick
<steele>
you can use c-m-x to send the current expression to the toplevel
<tantris>
hmm it does not really work, my file starts with #load "unix.cma" open Unix open Filename let is_directory filename = ...
<tantris>
if I send the first expression I get "Reference to undefined global `Unix'", and sending the #load "unix.cma" and open Unix does not work :(
noss has quit ["hej då"]
<karryall>
you have to put ;; after the #load
<tantris>
hmm it now jumps back to the first line where I have #!/usr/bin/ocamlrun /usr/bin/ocaml and gives Syntax error
<karryall>
just get rid of it
<tantris>
hmm okay I did, but why do I have to, if I run it as a script at the shell it works fine
<karryall>
in non-interactive mode the toplevel ignores the first line if it starts with #!
<tantris>
hmm maybe one could add to the caml.el something simmilar?
taw has left #ocaml []
Nutssh has quit [Read error: 110 (Connection timed out)]
tantris has left #ocaml []
Nutssh has joined #ocaml
jdmarshall has joined #ocaml
pattern has quit [Excess Flood]
pattern has joined #ocaml
blueshoe has joined #ocaml
jdmarshall has quit [Read error: 104 (Connection reset by peer)]
jdmarshall has joined #ocaml
housetier has joined #ocaml
Demitar has quit [Read error: 110 (Connection timed out)]
buggs|afk has joined #ocaml
buggs^z has quit [Read error: 110 (Connection timed out)]
Nutssh has quit ["Client exiting"]
housetier has quit ["#breaks @ irc.highteq.de"]
maihem has quit ["Client exiting"]
The-Fixer has quit ["Goodbye"]
The-Fixer has joined #ocaml
Nutssh has joined #ocaml
blueshoe has quit [Read error: 54 (Connection reset by peer)]
<Nutssh>
That seems underefficient. Why not 'let fn i = output_string meta ((string_of_int (snd x) ^ " ") in List.iter fn res' ?
<Demitar>
Ah, functional magic. ;-)
<Demitar>
I guess I'm thinking so much in list processing I'm missing the clean solutions. :)
<Nutssh>
:)
<Demitar>
I was just about to wrap all those iterations and maps into a functiona anyway. But this is much better anyway naturally. :)
<Riastradh>
You're doing imperative I/O. How can you expect to be functional?
<Demitar>
Riastradh, bah, it's just a matter of s/List.iter output_string/List.fold_left (^)/ anyway.
<Demitar>
Ah now I see what you mean. :)
<Demitar>
The switch is *to* an imperative way of doing it. :)
<Demitar>
I'll gladly blame that on being tired. :)
<Demitar>
But wait, I'm not switching to anything more imperative anyway.
* Demitar
is indeed not thinking at full speed. :)
<Smerdyakov>
Using ^ in printing code is pure waste to start with.
<Nutssh>
You don't wan to do '^', because its it does string cocatenation. Doing $n$ concatenations is O(n^2) time.
<Demitar>
The argument wasn't efficiency but programming style. :)
<Demitar>
Is this common or just showing my level of experience in OCaml/functional programming that I'm finding repeatedly simpler ways to do things even before I'm finished implementing them?
<Demitar>
Or lack thereof most likely.
<Nutssh>
:) Its a good thing. Just imagine how many lines of code that would be in C and how unclear it would be.
<Demitar>
Yes, I just now did match x with Unix.WEXITED n -> render n | Unix.WSIGNALED n -> render n | ... without noticing the obvious. :)
<karryall>
sorry, what is obvious ?
<Nutssh>
There's nothing wrong with that Demitar. I've done matches with duplicaates.
<Demitar>
That I could do render match x with Unix.WEXITED n -> n | ... instead.
<Demitar>
Since they're all ints.
<karryall>
yeah, except the two ints in WEXITED and WSIGNALED do not have the same meaning at all
<karryall>
one is return code, the other is a signal number ...
<Demitar>
Yes, what I'm actually doing is returning a string * int.
det has joined #ocaml
<Nutssh>
Focus on clarity.
<Demitar>
It is more clear to me. :)
<karryall>
Focus on correctness :)
lordjim has joined #ocaml
<Demitar>
I prefer to focus on working code. ;-)
<Demitar>
What I really like about ocaml is that I can write real crappy code and get away with it. :)
<Maddas>
Write now, make it work later!
<lordjim>
hi
<Demitar>
Hello lordjim.
<lordjim>
is there a purely functionnal way to replace for loops when dealing with arrays ?
<Demitar>
lordjim, arrays are per definition not functional.
<lordjim>
oki
<Demitar>
Or so I've been told. :)
<lordjim>
i'll make it with lists :)
<Demitar>
By the way, would this be cleaner if I used a Map? (I won't replace it since I needn't touch it but it would be good to know in the future.) Hashtbl.replace files dir ((data, file_name) :: (Hashtbl.find files dir))
<Nutssh>
Use arrays if you need em.
<lordjim>
yep but it look strange to use for and while in a functionnal looking language
<Demitar>
OCaml isn't pure functional anyway. :)
<Nutssh>
Functional is nice, but its not a pancea. Use the right tool.
<lordjim>
yes i see, but if i can make it the functionnal way, i prefer :)
<mellum>
Mhmm, pancake.
<lordjim>
but i'll end up using arrays i think :)
<Demitar>
Nutssh, just curious, but would you consider OO to be a correct tool? :) I've noticed many dislike them in favour of modules. :)
<Maddas>
Demitar: I find Functors to be very cool and even more powerful
<Nutssh>
Yes. OO is good when you want to inherit behavior or types in a sense that modules can't do easily without insane functor craziness.
<Nutssh>
Functors are good abstraction, but I pity having to understand code where everything goes through umpteen layers of functors.
<lordjim>
(even the word functor seems crazy)
<Demitar>
Now that I've got your attention. :) Could anyone of you fine gentlement be bothered to have a look at my old, top-sorted priority queue and point out the most blatant mistakes? (Well apart from the obviously braindead List.rev's.) It will probably be useful to know that I used it to implement A*.
<Nutssh>
I write my code in the functor style without using functors. IE, seperate modules for different components. Ready to be abstracted by fuctors if needed. Its surprising how rarely I've done that.
<mellum>
Doesn't the standard library have a priority queue?
<Nutssh>
List.rev is not stupid. Its O(1) per element. Stop microoptimizing. :)
<Demitar>
Nutssh, well I call it repeatedly. :)
<Demitar>
mellum, it does?
<Nutssh>
mellum: It has ordered trees, but I don't believe it has a priority queue as such.
<mellum>
Hm. Oh well.
<Nutssh>
Submit your implementation to the extlib project if it doesn't have one. Ocaml's library is way too stingy.
<Nutssh>
Demitar: URL?
<Demitar>
It's a bit too specialized for that I think actually.
<Demitar>
Nutssh, let me rummage around in my filesystem a bit. :)
<Demitar>
I guess my development dir is getting a bit crowded, takes a while for unison to even scan it. :)
<Nutssh>
You use unison too. :) Strange. I can do my homedir, 1gb, 20k files, in a minute.
<Nutssh>
Oh whoops. I meant the code you wanted us to take a look at.
<Demitar>
Hmm?
<mellum>
Demitar: Hmm, why don't you just use a heap if it's imperative anyway?
noss has joined #ocaml
<Demitar>
Well I can't guarantee this is the last version of it I did. And at the time I was most likely quite clueless about OCaml in general. (Looks at the code too.)
<Demitar>
mellum, well it's based on the assumption that this probably is faster than a heap, but perhaps a heap for the top bucket?
<Demitar>
s/probably/might be/
<Nutssh>
Arbitrary constraints on length like max_length are IMHO a bad idea. You need to factorize it into functions more. push should be at least 3 functions. 'find bucket' 'make bucket' 'push bucket' . ...
<mellum>
Well, heaps tend to be pretty damn fast, especially since you don't need any memory allocation
<Nutssh>
I'd also use an option type rather than magic min/max=max_int to represent emptiness.
<Demitar>
Nutssh, ah, yes that's probably part of my cluelessness at the time. :)
<karryall>
mellum: what do you mean you don't need any memory allocation ?
<Nutssh>
peek also isn't robust against an empty heap.
<mellum>
karryall: well, except when resizing the array, of course
<karryall>
ah, I thought you meant functional heaps
<Demitar>
Nutssh, I believe max_length was more of a tuning variable for setting the bucket sizes.
<Nutssh>
Whatever it is, the datastructure is a bit screweey. Ocaml has sum types. Embedding magic numbers into a datastructure is not suggested.
<Demitar>
Indeed.
<karryall>
some simple functional heaps are really easy to implement
<Nutssh>
purely functional datastructures?
<karryall>
yes
<Demitar>
This particular priorityqueue was of course optimized for A* and making the assumption that most of the items on the closed set would never be explored, thus only the top bucket was sorted.
<karryall>
yeah, see the leftist heap code is really small and simple
* Demitar
tries to summarize: replace the top bucket with a heap, use union types and factor things out into functions.
<Demitar>
Then I am of course ignoring "replace the evil top level game engine with something sensible". ;-)
<Demitar>
I of course made the mistake of thinking that providing multiple possible outputs would be a good idea (SDL and OpenGL). I of course now know that starting out with that is asking for a mess. :)
<mellum>
By the way, for A* you probably want a priority search queue where you can also search for an element. extlib contains one
<Demitar>
I'll have a look at it.
<Demitar>
In this case I used an array for direct lookup of cost and iirc I had a bit signifying if it was in the open or closed set.
<mellum>
but it depends on your search domain, if it is something explicitely represented like a terrain map you can just set a mark there when an element is in the PQ
<Demitar>
Indeed. What I would be interested in would be to do a vector (in contrast to tile) based game. But then I'd have to look into stuff like octrees and I'd rather wait a while. :)
<Demitar>
And either way, I don't currently have the computing power to draw any meshes (no native GL).
<Demitar>
Hmm. Would there be any point at all in using buckets of heaps?
<mellum>
Demitar: not really.
<Demitar>
Perhaps a combination, each bucket being a heap and an unsorted list. The list being empty in the topmost bucket.
<Demitar>
If we lose our top bucket we insert the unsorted elements into the heap. Probably hard to balance the bucket sizes though. Unless. Could it be so that it's quite trivial to split a heap by removing the top element?
<Demitar>
One could even split the bucket on each pop.
<Demitar>
The risk being that there'd be a lot of allocation.
<Demitar>
Perhaps each node in the heap would be an incomplete heap and an unsorted list instead... Or rather, a node could be a heap and a list but needn't be (rich datatypes coming to our rescue).
<Demitar>
Am I making any sense at all? :)
<Nutssh>
Don't overdesign. Do a simple heap implementation and then if profiling shows its a problem, THEN worry. :)
<Demitar>
Indeed. :) And that's actually what that priority queue was all about. :)
gim has joined #ocaml
gt2_ has joined #ocaml
Nutssh has quit ["Client exiting"]
lordjim has quit [Read error: 110 (Connection timed out)]
The-Fixer has joined #ocaml
fjb has joined #ocaml
gt2_ has quit [Read error: 110 (Connection timed out)]
lordjim has joined #ocaml
wazze has joined #ocaml
Nutssh has joined #ocaml
phubuh has quit [Remote closed the connection]
The-Fixer has quit ["Goodbye"]
The-Fixer has joined #ocaml
Maddas is now known as Riustradh
Riustradh is now known as Maddas
door has quit [Read error: 60 (Operation timed out)]