<hcarty>
derdon: The BatFoo.print functions are for use with the BatPrint.*printf functions.
<hcarty>
derdon: If you have the Batteries syntax extensions in use (specifically estring) then you can type "BatPrint.printf p"%{int array}\n" [|1; 2; 3|]" to have nice array printed output.
<hcarty>
(BatPrint = Print if you "open Batteries" in your code, of course)
<derdon>
hcarty: I don't know whether the Batteries syntax extensions are enabled
<derdon>
hcarty: I installed ocaml-batteries with apt-get in ubuntu 10.04
<hcarty>
derdon: This part of the estring syntax extension allows you to define your own printers for your own types and use them relatively easily
<hcarty>
derdon: How are you using batteries? In the toplevel or from compiled code?
<hcarty>
derdon: You need to use camlp4 and the batteries.pa_string.syntax findlib package to enable the extension I think
<hcarty>
Or if you use the Batteries-provided toplevel initialization code that should provide you with the syntax extensions as well
jimmyb2187 has quit [Ping timeout: 265 seconds]
<derdon>
hcarty: oh yes, the extensions are loaded in the toplevel
<hcarty>
derdon: Then you should be able to do "Print.printf p"%{int array}\n" [|1; 2; 3|];;" and get something very similar to "[|1; 2; 3|]" as output
<hcarty>
The "p" before the string is what tells the syntax extension to dig in and do its thing
<derdon>
ok, I will try it
<hcarty>
Most Batteries modules should support this (List, Hashtbl, etc.)
<derdon>
hcarty: your example works well
<derdon>
hcarty: but I don't know how to specify the type "array (list string)"
<derdon>
if I try it like this, a Parse error is printed
<hcarty>
derdon: You probably want "string list array" -- the toplevel gets messed up and uses revised syntax
<hcarty>
when syntax extensions are loaded
<derdon>
why does the toplevel behave different than regular *.ml files?
<hcarty>
derdon: Something along the lines of "Print.printf "%{string list array}\n" my_value"
<hcarty>
derdon: Not sure - it's a bug in some part of the system, either the toplevel, camlp4, findlib or the method Batteries uses to load the extensions
<derdon>
yay, it works now!
<derdon>
thanks a lot!
<hcarty>
derdon: But only the types reported by the toplevel are affected - not the code you enter
<hcarty>
You're very welcome, glad it works!
<derdon>
hcarty: do I have to pay attention to anything when I compile the file because of the use of syntax extensions?
<derdon>
hm, yes. "unbound value p"
<derdon>
where is this value defined?
sepp2k has quit [Quit: Leaving.]
<hcarty>
How are you compiling your program?
<hcarty>
The syntax extension is defined in the batteries.pa_string.syntax
<hcarty>
And camlp4o is needed
<derdon>
wait a moment, I will paste the file
<hcarty>
derdon: Are you using ocamlbuild?
<derdon>
I use currently a simple bashscript which executes some commands
<derdon>
no
<derdon>
I use no buildsystem at all :D
<hcarty>
Ah, ok - if you paste the bash script to a pastebin that should help
<hcarty>
Try adding this to your ocamlfind lines: -package batteries.pa_string.syntax -syntax camlp4o
bzzbzz has joined #ocaml
<hcarty>
I think that is what you need
ccasin has joined #ocaml
<derdon>
ok
<derdon>
ocamlfind says the META variable 'preprocessor' must be set
<derdon>
how do I set META variables?
<derdon>
does it have something to do with Makefiles?
jimmyb2187 has joined #ocaml
<hcarty>
derdon: I'm not sure - I normally do this with ocamlbuild :-)
<hcarty>
I thought that the "-syntax camlp4o" would do that part...
<hcarty>
This works for a simple test file on my system: "ocamlfind c -syntax camlp4o -thread -package batteries,batteries.pa_string.syntax -linkpkg test.ml"
<hcarty>
I suppose the order of arguments may matter
<hcarty>
Though it doesn't seem to for this
<hcarty>
derdon: Can you pastebin your new compilation script?
<derdon>
yes
<derdon>
oh, wait
<derdon>
do I have to pass the option "package" twice?
<derdon>
once for the batteries in general and once for the syntax extensions?
<hcarty>
derdon: Yes, or include the packages together as "-package batteries,batteries.pa_string.syntax"
<derdon>
I see. I'll the use the comma-seperated version
<hcarty>
If you enter [1;2;3] in the toplevel, it will tell you it's a list int rather than an int list (if you are using a syntax extension)
<derdon>
I see
<derdon>
and how can I avoid my "new" problem?
<hcarty>
derdon: Are you using Print.printf or Printf.printf?
<hcarty>
You need to use Print.printf and from the look of the error you are using Printf.printf
<derdon>
Printf.printf
<hcarty>
That's the error then :-)
<derdon>
okay, I am really confused by the huge amount of functions which look that similar
<hcarty>
derdon: Yes, there is definitely a lot of overlap
<flux>
derdon, well, you're not going to have it, sorry :)
<flux>
derdon, toplevel has secret information that's not available for programs
<hcarty>
derdon: The easiest way to think about it is that the Print module is a replacement for the Printf module, but rather than using using OCaml's built-in printf-like string interpolation, it uses the pa_string syntax extension to create a more flexible/more easily extensible printing mechanism
<flux>
..that's pretty exact way of looking at it, aswell?
<derdon>
now it really works =) thanks again, guys!
<hcarty>
flux: Probably so
patronus has quit [Ping timeout: 240 seconds]
<hcarty>
derdon: Excellent, glad to hear it
<derdon>
flux: are you one the authors of the batteries?
<flux>
I guess strictly speaking that is correct, there is some of my code in Batteries..
<derdon>
so you're not an official dev of them but a contributor who spent much time for it
barismetin has joined #ocaml
<flux>
correct, except not a lot of time :)
rgrig has joined #ocaml
vpalle has joined #ocaml
jakedouglas has joined #ocaml
joewilliams_away is now known as joewilliams
patronus has joined #ocaml
rovar has joined #ocaml
ttamttam has quit [Quit: Leaving.]
itewsh has joined #ocaml
avsm has joined #ocaml
avsm has quit [Client Quit]
avsm has joined #ocaml
jonafan_ is now known as jonafan
jimmyb2187 has left #ocaml []
ftrvxmtrx has quit [Quit: Leaving]
itewsh has quit [Quit: There are only 10 kinds of people: those who understand binary and those who don't]
fraggle_ has quit [Quit: -ENOBRAIN]
rgrig has quit [Quit: Leaving]
leino has quit [Quit: leaving]
fraggle_ has joined #ocaml
fraggle_ has quit [*.net *.split]
fraggle_ has joined #ocaml
vpalle_ has joined #ocaml
dark has quit [Read error: Connection reset by peer]
vpalle has quit [Ping timeout: 260 seconds]
brooksbp_ has joined #ocaml
brooksbp has quit [Ping timeout: 268 seconds]
drk-sd has quit [Quit: {'EXIT', drk-sd, "bye"}]
ftrvxmtrx has joined #ocaml
oriba has joined #ocaml
avsm has quit [Quit: Leaving.]
avsm has joined #ocaml
vpalle__ has joined #ocaml
jimmyb2187 has joined #ocaml
vpalle_ has quit [Ping timeout: 240 seconds]
rovar has quit [Ping timeout: 265 seconds]
avsm has quit [Remote host closed the connection]
sepp2k has joined #ocaml
brooksbp_ has quit [Quit: Leaving...]
itewsh has joined #ocaml
drunK has joined #ocaml
_unK has quit [Ping timeout: 260 seconds]
ikaros has quit [Quit: Leave the magic to Houdini]
thieusoai has joined #ocaml
_unK has joined #ocaml
drunK has quit [Ping timeout: 240 seconds]
alpounet has left #ocaml []
boscop__ has joined #ocaml
boscop_ has quit [Ping timeout: 260 seconds]
segmond has quit [Ping timeout: 265 seconds]
ygrek has joined #ocaml
<derdon>
can I set variables global within functions?
<derdon>
or is the only possible solution to pass this value on to other functions which need it?
<hcarty>
derdon: Passing values is generally the cleaner approach. You can modify a global reference if you really want to though.
<hcarty>
Insanity and despair lie down that road though :-)
vpalle_ has joined #ocaml
vpalle__ has quit [Ping timeout: 245 seconds]
<derdon>
hcarty: but not when the reference is declared locally in a function
vpalle__ has joined #ocaml
vpalle_ has quit [Ping timeout: 258 seconds]
rovar has joined #ocaml
<flux>
derdon, the scope of variables is purely lexical
<flux>
so a variable definition cannot escape its scope
<derdon>
flux: I see
<derdon>
I have to see this as an advantage
<flux>
it is. when you are reading the code :)
<derdon>
yes
<derdon>
and when someone tries to debug it
drk-sd has joined #ocaml
gareth_0 has joined #ocaml
<gareth_0>
hi
<adrien>
=)
vpalle_ has joined #ocaml
<gareth_0>
would be it be an accurate assertion that objects can make ocaml more concise because of not having to type out module names, but that the large infered types are more difficult to debug and type constraints are often needed for polymorphism?
barismetin has quit [Remote host closed the connection]
<gareth_0>
this would explain the slight disdain i detect for object, maybe?
<flux>
I think the disdain is more due to the mindset of thinking functionally than thinking imperatively - which objects in most cases make you do.
<flux>
by sending commands to objects you change their state
<flux>
that being said, ocaml does provide nice support for immutable objects
<flux>
and otherwise ocaml's object system is quite neat, even though it does need, as you said, some type annotations at times
ygrek has quit [Ping timeout: 245 seconds]
<gareth_0>
i see
vpalle__ has quit [Ping timeout: 240 seconds]
<flux>
I personally will happily use object system and especially so if it is the nice solution for the problem (for example I need to use inheritance or other form of polymorphism that are nice with objects)
<flux>
oh, and it's nice that it does reduce the Foo.Bar.Baz-notation quite a bit aswell
<adrien>
my main reluctance with objects is that it makes type-checking somehow weaker and sometimes I have troubles finding the error
<flux>
another practical aspect: objects aren't as fast in ocaml as modules are. so that might matter if you do small things that get called a lot (say, lexers and big files)
<flux>
I wouldn't say it makes it weaker. you will want to annotate your codes at places to avoid unwieldly error messages though. practice, practice ;)
<adrien>
I always end up annotating, but I'm not used to ;-)
<flux>
with the new first class modules support in 3.12 it might be that objects have even less use than they used to, though..
<flux>
basically what I have had is one module per one bigger class anyway (unless the classes are heavily related)
<gareth_0>
do you think polymorphic records would be useful?
<gareth_0>
you could pattern match over them, unlike objects
<flux>
what kind of records do you mean? like the ones in SML?
<flux>
there are some pattern matching syntax extensions for objects..
gareth_000 has joined #ocaml
gareth_0 has quit [Ping timeout: 248 seconds]
ccasin has quit [Quit: Leaving]
<det>
objects cant express some useful things that modules can
vpalle__ has joined #ocaml
gareth_000 has quit [Ping timeout: 246 seconds]
barismetin has joined #ocaml
vpalle_ has quit [Ping timeout: 258 seconds]
vpalle__ has quit [Ping timeout: 240 seconds]
Associat0r has joined #ocaml
fschwidom has joined #ocaml
gareth_000 has joined #ocaml
virtuoussin13 has joined #ocaml
oc13 has quit [Ping timeout: 240 seconds]
oriba has quit [Quit: Verlassend]
ReachingFarr has joined #ocaml
segmond has joined #ocaml
<ReachingFarr>
So I have some .cmo files in a directory that has a relative path of "../frontend" from where I'm trying to compile a program that uses those objects. I passed "-I ../frontend/" to ocamlc, but I'm still getting a "Reference to undefined global" error. What am I doing wrong?
enthymeme has joined #ocaml
gareth_000 has quit [Ping timeout: 258 seconds]
virtuoussin13 has left #ocaml []
seg_ has joined #ocaml
segmond has quit [Ping timeout: 252 seconds]
<derdon>
this script causes the error message "Error: unbound value bar" in line 2: http://bpaste.net/show/6259/
<derdon>
can someone explain me why?
<Submarine>
that's normal
<Submarine>
bar is not defined before being used
<derdon>
are the parts right of the arrow of a pattern matching restricted in any way?
* derdon
head -> table
<derdon>
omg
<derdon>
Submarine: it seems that it's not my day today :S
<derdon>
ok, I have to use "let foo = ... and bar = ..."
<derdon>
no, it's "let rec foo = ... and bar = ..."
Anarchos has joined #ocaml
itewsh has quit [Quit: There are only 10 kinds of people: those who understand binary and those who don't]
Submarine has quit [Quit: Leaving]
Anarchos has quit [Quit: Vision[0.9.7-H-090423]: i've been blurred!]
vpalle has joined #ocaml
<ReachingFarr>
Can anyone help me compile this stupid file? It needs some objects from another directory and I can't get ocamlc to find them.
<derdon>
ReachingFarr: have you already tried an absolute path?
<ReachingFarr>
derdon: I would prefer a solution that didn't involve an absolute path. It's not like everyone is going to be compiling this code in the same place.
<derdon>
ReachingFarr: answer the question, my friend ;)
<ReachingFarr>
I have not used absolute paths, no.
<derdon>
ReachingFarr: do you really from where ocamlc starts the search in case of relative paths?
<mfp>
ReachingFarr: are the corresponding .cmi also in ../frontend?
<ReachingFarr>
Well, I would think it would start from the pwd, and then continue on with the directories passed with the -I option.
<ReachingFarr>
mfp: Yes.
<derdon>
ReachingFarr is too scared to tries absolute paths :P
<derdon>
*to try
barismetin has quit [Remote host closed the connection]
<ReachingFarr>
derdon: Sure, scared. Or they wouldn't actually solve my problem.
<mfp>
ReachingFarr: what's the exact error message you're getting? My ocamlc (3.11.1) complains with something like Error: Unbound value Foo.a
seg_ is now known as segmond
<ReachingFarr>
OK. So I have a file called TangleLexDbg.ml that has the line "open TangleLexer" in it. I'm using this command to compile it: `ocamlc -I ../frontend/ -o tangle-lexdbg TangleLexDbg.ml ../frontend/TangleLexer.cmo ../frontend/TangleParser.cmo` I get this error: "Error: Error while linking TangleLexDbg.cmo: Reference to undefined global `TangleLexer'"
<ReachingFarr>
Ya, that fixed it. I think I now remember running into this earlier.
<ReachingFarr>
Thanks for the help mfp.
<mfp>
np
<mfp>
the pb was in the linker, which is why I didn't recognize the error msg as coming from the compiler :) (figured it out 1 sec before you pasted your cmdline by grepping the compiler sources :)
<ReachingFarr>
Haha, thanks. It seems kinda silly that the object files need to be in a specific order.
<mfp>
it's because of the side effects in their initialization
<mfp>
since you can have let () = ... in your modules
<mfp>
so, while the compiler/linker could infer an ordering that leaves no unresolved symbols, it cannot guess _the_ correct order as far as side effects are concerned
<ReachingFarr>
Fair enough. Just something I have to get used to and then remember later.
vpalle_ has joined #ocaml
enthymeme has quit [Quit: rcirc on GNU Emacs 23.1.1]
vpalle has quit [Ping timeout: 258 seconds]
<derdon>
omg, ocamls way of printing backtraces is useless
fschwidom has quit [Remote host closed the connection]
sepp2k has quit [Quit: Leaving.]
<orbitz>
derdon: how so?
<derdon>
orbitz: comiled files are simply called "unknown location"...
<derdon>
*compiled
<orbitz>
ah yess limited to bytcode compiled or somethign