<Riastradh>
Damnit, caml.inria.fr really needs to be more reliable.
<Smerdyakov>
There may be an algorithm for that.
Kinners has joined #ocaml
lament has joined #ocaml
__DL__ has quit [Read error: 110 (Connection timed out)]
mrvn_ has joined #ocaml
PsionV has joined #ocaml
Smerdyakov has quit [Read error: 104 (Connection reset by peer)]
PsionV is now known as Smerdyakov
mrvn has quit [Read error: 110 (Connection timed out)]
reltuk has quit [asimov.freenode.net irc.freenode.net]
Smerdyakov has quit ["sleep"]
reltuk has joined #ocaml
lament has left #ocaml []
rhil_atlanta is now known as rhil_zzz
Kinners has left #ocaml []
mattam has joined #ocaml
<reltuk>
is tuareg mode much better than caml mode that comes with xemacs?
<async>
it says that i cannot define an instance variable using another instance variable.. what are some common ways around this (besides class creation arguments)?
Yurik has joined #ocaml
Yurik_ has quit [Read error: 104 (Connection reset by peer)]
<mrvn_>
async: class foo = let t1 = blub in let t2 = bla t1 in object var a = t1 var b = t2 end
<mrvn_>
reltuk: I find it much better
gene9 has joined #ocaml
<async>
mrvn_: thanks a lot man.. that helps a LOT
gene9 has quit []
mattam has quit [asimov.freenode.net irc.freenode.net]
reltuk has quit [asimov.freenode.net irc.freenode.net]
mrvn_ has quit [asimov.freenode.net irc.freenode.net]
docelic has quit [asimov.freenode.net irc.freenode.net]
Zadeh has quit [asimov.freenode.net irc.freenode.net]
smkl has quit [asimov.freenode.net irc.freenode.net]
vegai has quit [asimov.freenode.net irc.freenode.net]
gl has quit [asimov.freenode.net irc.freenode.net]
pattern_ has quit [asimov.freenode.net irc.freenode.net]
polin8 has quit [asimov.freenode.net irc.freenode.net]
Yurik has quit [asimov.freenode.net irc.freenode.net]
karryall has quit [asimov.freenode.net irc.freenode.net]
liyang has quit [asimov.freenode.net irc.freenode.net]
wax has quit [asimov.freenode.net irc.freenode.net]
lam has quit [asimov.freenode.net irc.freenode.net]
Riastradh has quit [asimov.freenode.net irc.freenode.net]
rhil_zzz has quit [asimov.freenode.net irc.freenode.net]
foxster has quit [asimov.freenode.net irc.freenode.net]
mellum has quit [asimov.freenode.net irc.freenode.net]
Yurik has joined #ocaml
mattam has joined #ocaml
reltuk has joined #ocaml
mrvn_ has joined #ocaml
karryall has joined #ocaml
docelic has joined #ocaml
vegai has joined #ocaml
liyang has joined #ocaml
wax has joined #ocaml
smkl has joined #ocaml
Zadeh has joined #ocaml
lam has joined #ocaml
pattern_ has joined #ocaml
Riastradh has joined #ocaml
gl has joined #ocaml
rhil_zzz has joined #ocaml
polin8 has joined #ocaml
foxster has joined #ocaml
mellum has joined #ocaml
asqui has quit [Excess Flood]
__DL__ has joined #ocaml
asqui has joined #ocaml
Slackwarrior has joined #ocaml
<Slackwarrior>
hello people!
shinig has joined #ocaml
shinig is now known as shining
<Slackwarrior>
hello shining ;)
<Slackwarrior>
please talk in english here
<Slackwarrior>
(parla in inglese)
<Slackwarrior>
people can i ask a question?
<shining>
hello!
<Slackwarrior>
is there anyone?
<shining>
no
<Slackwarrior>
welll.
<Slackwarrior>
i got a set of terms defined in the following way:
<Slackwarrior>
every integer const is a term
<Slackwarrior>
a variable is a term
<Slackwarrior>
taken a funcction f and k terms t1,...,tk the term in f(t1,...,tk)
<Slackwarrior>
i can represent the set of terms as:
<Slackwarrior>
type term = Const of int | Var of string | Term of string * term list;;
<Slackwarrior>
a substitution is a list of couples (xi,ti) for i=1,...,k so that xi != xj for i != j
<Slackwarrior>
the application of a substitution s on a term t is the replacement of all the variables xi in t with ti
<Slackwarrior>
hellooooo?????
<__DL__>
I'haven't seen any question here
<__DL__>
I'haven't seen any question here
<Slackwarrior>
ah
<Slackwarrior>
i thought noone was reading
<Slackwarrior>
ok i go on
<Slackwarrior>
for example if i got t=f(x,g(y)) and the substitution S=[(x,h(y,0));(y,g(1))] then the result is f(h(y,0),g(g(1)))
<Slackwarrior>
the substitutions are done simultaneously otherwise i get f(h(g(1),0),g(g(1)))
<__DL__>
by the way, this look like homework, you might no have very interesting answer...
<Slackwarrior>
now we got two terms t and p
<Slackwarrior>
t matches with p if there is a substitution S so that S(p)=t
<Slackwarrior>
how can i write a function that taken p and t it answers that there exists a substitution S that changes p into t?
<Slackwarrior>
to represent the result of a matching we can define the type:
<Slackwarrior>
type matchres = NoMatch | Subst of (string * term) list;;
* mrvn_
likes people that just message me talking to the xemacs doctor. :)
<mrvn_>
You should relabel all your Var to be unique and then its just a simple recursive search&replace.
<mrvn_>
Term.map would be the right function
<Slackwarrior>
huh
<Slackwarrior>
no no . i have to keep the term declaration
<mrvn_>
or rather Term.fold here
<Slackwarrior>
i have to use: type term = Const of int | Var of string | Term of string * term list;;
<Slackwarrior>
how can i write a function that takes p and t and says if there exists a substitution S so that S(p)=t???
<mrvn_>
You can still write a map and a fold function
<Slackwarrior>
i dont even know what they are
<mrvn_>
let is_subst (Subst(name, term)) p = p = name
<mrvn_>
and fold that over all substitutions.
<mrvn_>
Never used List.map or List.fold_*?
<Slackwarrior>
no never
<mrvn_>
Map and fold are pretty generic concepts.
<Slackwarrior>
can i do that withouyt using maps and folds?
<mrvn_>
It would still be a kind of fold however you write it.
<Slackwarrior>
oh it's the same :)
<mrvn_>
no, they are both quite different. About 10 chars different.
<Slackwarrior>
ok ok
<mrvn_>
(for lists that is)
<Slackwarrior>
let's do the longer one
<Slackwarrior>
longest
<mrvn_>
map applies a function to each elemnt in turn while fold folds each element in turn with an accumulator seeded with an initial element.
<Slackwarrior>
i dont wanna use them :)
<mrvn_>
You can't get around the concept. Pretty much anything you do resembles a fold.
<Slackwarrior>
ah
<Slackwarrior>
by the way i dont wanna see if , taken a substitution S and 2 terms p and t, S(p)=t
<Slackwarrior>
i wanna see if S exists
<mrvn_>
you can't. that equivalent to the halting problem.
<mrvn_>
more specific you can write a function that says an S exists for some/most p and t but some p/t combinations might never give you a result.
<Slackwarrior>
then i dunno what to do
<mrvn_>
How many substitutions are allowed? Maybe only one iteration?
<Slackwarrior>
yes
<mrvn_>
Then you can compare the two terms and see if any differences are a variable in the first term and a term in the other. Each gives you a substituion. Any difference without a var in the first term makes it impossible.
<Slackwarrior>
ummm
<Slackwarrior>
tell me the algorithm
<mrvn_>
You only have var->term substitutions, right?
<Slackwarrior>
no
<Slackwarrior>
i can substitute anything
<Slackwarrior>
wait
<Slackwarrior>
there talks about variables
<mrvn_>
anything? Then its dead easy. For every p and t there exists the trivial substitution p->t
<Slackwarrior>
ummm
<Slackwarrior>
no no
<Slackwarrior>
there just variables
<mrvn_>
That makes it easiers and solveable.
<Slackwarrior>
for examnple S={(x,h(y,0)); (y,g(1)))
<Slackwarrior>
it substtitutes every x with h(y,0) and every y with g(1)
<mrvn_>
its a simple compare of the two terms and noting all diferences.
<Slackwarrior>
tell me tell me
<Slackwarrior>
:)
<mrvn_>
I just did, twice.
<Slackwarrior>
can you write the function please?
<mrvn_>
I believe thats your homework
<Slackwarrior>
ok ok
karryall has quit [Remote closed the connection]
<Slackwarrior>
mrvn_: i've thought to a function but i dunno how to put in ocaml
<Slackwarrior>
can you help me please?
karryall has joined #ocaml
lam has left #ocaml []
lam has joined #ocaml
taw has joined #ocaml
<taw>
how to define new operators in ocaml ?
<mellum>
let (+!) x y = Int64.add x y
<taw>
are there any limits about how may it look like ?
<mellum>
Yes, only certain characters are allowed.
<mellum>
But I think something like +@!#@! is allowed :)
<taw>
it works with /! but not with !/
<taw>
weird
<mellum>
no, # is not allowed
<mellum>
! is unary prefix.
<mellum>
the first character determines the arity.
<mellum>
and precedence.
<taw>
hmm
<taw>
is @ ok ?
<taw>
@+ @- etc ?
<taw>
i need a few operators on vectors
<mellum>
I guess so
<mellum>
Well, I would be careful with that and only define those where precedence etc is clear
<taw>
oh
<mellum>
otherwise it would probably be hard to read
<taw>
dot_product (vector_add x y) z
<taw>
can't be harder than that
<mellum>
well, you can probably use +! or +@ for add. dot product doesn't quite fit in. Should it have higher or lower precedence than +?
<taw>
they aren't mixable anyway
Smerdyakov has joined #ocaml
<Zadeh>
hrm, are there any languages where you could define some arbitrary graphical symbol?
<Smerdyakov>
What would that mean?
<taw>
like perl ?
<Zadeh>
well, it'd be cool to use mathematical notation
<taw>
perl6 is supposed to allow full abuse of unicode ;)
<Zadeh>
Look pretty, but not easy to input I s'pose
<Zadeh>
hehe
<taw>
any unicode characters in functions and operator names
<taw>
that sounds great ;)
<Zadeh>
great
<taw>
i'm going to use some chinese characters ;)
<Zadeh>
should really enhance any obfuscated perl programming contests
<taw>
yeah
<taw>
especially having many names that look the same but are encoded different way in unicode
<taw>
like russian vs. latin letters, or CNF vs. DNF ;)
<taw>
ok, bye
taw has left #ocaml []
mkfort has joined #ocaml
<Slackwarrior>
let rec matchterm (t,p)= match (t,p) with1=s2 then matchlists(l2,l1) else fals (Term(s2,l2),Term(s1,l1)) -> if s1=s2 then matchlists(l2,l1) else false |(Var(s2),Term(s1,l1)) -> false
<Smerdyakov>
Stop pasting so much, or people will get Angry at you.
<docelic>
retard.
<mrvn_>
whats null?
<mrvn_>
you can#t name two things null
<Slackwarrior>
ah ok
<Slackwarrior>
sorry
<Slackwarrior>
null as empty list
<Slackwarrior>
or nil???
<Slackwarrior>
ummm
<mrvn_>
no, your binding something to null, twice
<Slackwarrior>
i messing a bit of c with a bit of ocaml
<Slackwarrior>
nil doesnt work
<mrvn_>
[]
<Slackwarrior>
ah ok
<Slackwarrior>
now i messed with a bit of standard ml
<Slackwarrior>
mrvn_: can i paste you my function?
<Slackwarrior>
or send the file
<mrvn_>
why should you?
<mrvn_>
Seen it twice already
<Slackwarrior>
now it's correct
<Slackwarrior>
you should tell me if it really works
<Slackwarrior>
:)
<mrvn_>
does it compile?
<Slackwarrior>
yes
<mrvn_>
does it performe as it should?
<mrvn_>
do you own homework
<Slackwarrior>
dunno
<Slackwarrior>
this homework sucks
<Slackwarrior>
aaahh... the advantages of imperative programming....
* Smerdyakov
steps on Slackwarrior once.
* Smerdyakov
steps on Slackwarrior twice.
<Slackwarrior>
it doesnt work :(
<Smerdyakov>
Oh, sorry.
* Smerdyakov
steps on Slackwarrior thrice.
thedark has joined #ocaml
<thedark>
an exception has been raised, and i cant figure out how to know the exact line from my program where the error occured .. ideas?
<mrvn_>
what exception?
<Slackwarrior>
mrvn_; im getting crazy!!! pleeeeaaassse help me!!!
<thedark>
its a "custom exception" raised for a library of mine...
<mrvn_>
Than look where it appears in the source. Its your code fix it yourself.
<mrvn_>
and throw more meaningfull exceptions next time
<thedark>
i think u've misunderstood my question...the function "foo"raising the exception is ok... i want to know what line of another program has been calling foo...
docelic is now known as docelic|away
bew_ has joined #ocaml
bew_ has left #ocaml []
lus|wazze has joined #ocaml
docelic|away is now known as docelic
bew_ has joined #ocaml
bew_ has left #ocaml []
bew_ has joined #ocaml
<bew_>
anybody here?
<Smerdyakov>
Oh yes.
<bew_>
does anybody use the labelling mode?
<bew_>
I don't like it.
<Smerdyakov>
I don't really use OCaml yet. ;-)
<bew_>
what do you use now?
<Smerdyakov>
Standard ML
<lus|wazze>
whats not to like about the labels in ocaml?
<bew_>
too lot of writing if you have only few arguments per function
<lus|wazze>
then dont use it for such functions
<lus|wazze>
labeling is really only meant for functions with lots of arguments whose order would be too hard to memorize
<bew_>
well, I switched from 3.02 to 3.06 and the compiler complained about missing labels
<lus|wazze>
hm maybe you compiled it with the completely "labelized" standard library
<bew_>
I tried to fix my 18.000 LoC, but ended up with -no-labels
<lus|wazze>
i dont like that either
<lus|wazze>
hm :/
<lus|wazze>
thats strange
<lus|wazze>
usually functions with unlabeled arguments should still be working fine
<bew_>
I will try it again.
<bew_>
Is there a tool that converts from SML to OCaml or vice versa?
<Smerdyakov>
I don't know, but it would be easy to write if you exclude OO stuff.
<Smerdyakov>
And translating library calls, I guess. :D
<bew_>
i exlude the OO stuff anyway.
<bew_>
but some important libraries (pxp, an XML lib) use it extensively
mattam_ has joined #ocaml
* bew_
looks for something to eat in Budapest
bew_ has left #ocaml []
thedark has left #ocaml []
Smerdyakov has quit ["eh?"]
mattam has quit [Read error: 60 (Operation timed out)]
mattam_ is now known as mattam
Smerdyakov has joined #ocaml
Smerdyakov has quit ["brb"]
Smerdyakov has joined #ocaml
TachYon has joined #ocaml
lus|wazze has quit ["Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Univ]
<Slackwarrior>
help me pleeeeaaaassssse
<Riastradh>
With what?
<Slackwarrior>
a homework
<Slackwarrior>
it's too difficult
<Slackwarrior>
(in my opinion it's impossible)
* docelic
rolls around
<Slackwarrior>
can i send you what ive written?
<docelic>
you have pasted already
<Slackwarrior>
no
<Slackwarrior>
it's a debugged version
<docelic>
oh, from bad to worse
<Slackwarrior>
but i have done a function that returns a boolean value, not a matchres value
<Slackwarrior>
it works
<Slackwarrior>
docelic; please help me! you wont see me here anymore!
<Slackwarrior>
if i got type matchres= NoMatch | Subst of (string * term) list;;
<Slackwarrior>
how can i add an element to that Subst?
karryall has joined #ocaml
<Riastradh>
Subst elem :: foo
<Riastradh>
er.
<Riastradh>
Subst (elem :: foo)
<Slackwarrior>
it doesnt work
<Riastradh>
What 'doesn't work' about it?
<Slackwarrior>
you dont understand until i send you my program :(
<Riastradh>
Well. What do you mean 'add an element to that Subst?'
<Slackwarrior>
i dunno anymore
<Slackwarrior>
please give a look to my program
<mrvn_>
let add_subst subst var term = Subst ((name, term) :: (match subst with Subst list -> list | NoMatch -> [])
<mrvn_>
That should do it
<Slackwarrior>
ummm
<Slackwarrior>
syntax error
<mrvn_>
where?
<Slackwarrior>
Syntax error: ')' expected, the highlighted '(' might be unmatched
<Slackwarrior>
corrected
<Slackwarrior>
Unbound value name
<mrvn_>
s/name/var/
<Slackwarrior>
val add_subst : matchres -> string -> term -> matchres = <fun>
<mrvn_>
Since when is that one argument to add_subst a string?
<mrvn_>
and add_subst takes tree arguments in my form
<mrvn_>
Stop writing C with its () around arumengts of a function.
<mrvn_>
matchterms returns a matchres and matchlist too?
<mrvn_>
Then you need a function that merges two matchres into one.
Smerdyakov has joined #ocaml
<mrvn_>
clear?
<Slackwarrior>
yes
<Slackwarrior>
but i messed something in my function
<Slackwarrior>
i rewrite it from scratch :(
<mrvn_>
Try not to use () for function arguments
<Slackwarrior>
why?
<Riastradh>
You get the advantages of currying and partial application if you use curried functions instead of functions of tuple arguments.
<Riastradh>
s/tuple arguments/a single tuple argument/1
<Slackwarrior>
ah ok
<Slackwarrior>
for example i write this new function
<Slackwarrior>
let rec matchtermslist t,p,l = match t,p with.....
<Slackwarrior>
but it doesnt work
<Slackwarrior>
i wanna match only t and p
<mattam>
match (t,p)
<Slackwarrior>
syntax error
<mattam>
and no , in your arguments list AFAIK
<Slackwarrior>
what?
<mattam>
t,p,l -> t p l or (t,p,l)
<Riastradh>
Use: let rec matchtermslist t p l = match (t,p) with ...
<Slackwarrior>
ah ok
<mrvn_>
(a,b) is the same as a,b. The () are just for readability around tuples.
<mattam>
i.e. curried or uncurried form
<mattam>
really ?
<Slackwarrior>
it works!
<Slackwarrior>
can i do
<mrvn_>
let rec matchtermslist l = function (Val v, Term t) -> ... is probably what I would do.
<Slackwarrior>
l=l::(t,s)?
<Slackwarrior>
l is a list
<mrvn_>
Slackwarrior: no
<Slackwarrior>
i wanna enqueue elements
<mrvn_>
(t,s)::l
<Slackwarrior>
l=(t,s)::l ?
<mrvn_>
If you need to add elements to the end of a list you can do so with l@[(t,s)] but thats very expensive. Usualy when one needs that its far better to enqueue elements at the start and List.rev the list at the end.
<mrvn_>
Slackwarrior: let l = (t,s) :: l in .... You can#t enqueue anything to l but create a new l bound to a new list with that extra element.
<Slackwarrior>
ah ok
lus|wazze has joined #ocaml
<Slackwarrior>
mrvn_: can you please modify my function? i dont really know what to do
<Smerdyakov>
Slackwarrior, what to do is ASK AN INSTRUCTOR.
<lus|wazze>
what do you want your function to do?
<Slackwarrior>
ummmm
<Slackwarrior>
you got a term that can be an integer constant or a variable or a function
<Slackwarrior>
it is defined as
<mrvn_>
I'm guessing your hearing some functional programming lecture. Don't you have a script for it or a book?
<Slackwarrior>
type term = Const of int | Var of string | Term of string * term list;;
<Slackwarrior>
yes but there isnt written how to do this stupid exercise
<Slackwarrior>
if you got a=f(x,g(y)) then it's represented as let a=Term("f", [Var "x"; Term("g",[Var "y"])]);;
<mrvn_>
Look for pointers about learning ocaml or go fetch a tutorial and do that first.
<mellum>
You mean it has exercises without immediatley giving the answers? What a moronic book.
<Slackwarrior>
if you got b=f(h(y,0),g(g(1))) then it's represented as let b=Term("f", [Term("h", [Var "y"; Const 0]); Term("g", [Term("g", [Const 1])])]);;
<mrvn_>
You don't seem to have used ocaml before.
<Slackwarrior>
i never used ocaml before
<Slackwarrior>
the prof explained something of ocaml and gave us an exercise to resolve in 6 days
<Slackwarrior>
a substitution is a list of couples (xi,ti) where xi != xj for i != j
<Slackwarrior>
S=[ (x1,t1); .... ; (xk,tk) ]
<Slackwarrior>
for example between a and b there is the substitution S=[ (x,h(y,0)); (y,g(1))]
<Slackwarrior>
now ive written a function that says if there exists a substitution between two terms
<mattam>
unification...
<Slackwarrior>
but it return a boolean value
<Slackwarrior>
the prof wants us to return the whole substitution
<Slackwarrior>
the return value is defined as
<Slackwarrior>
type matchres = NoMatch | Subst of (string * term) list;;
<Slackwarrior>
how the hell have i to modify my function???
<Slackwarrior>
it's impossible ( i think)
<mattam>
i think if you can say that there is a substitution then you should know which one
<Slackwarrior>
yes but it's impossible to return it with that type!
<mattam>
why is that ?
<mrvn_>
The only thing missing in your code is the merging of two substitutions.
<Slackwarrior>
huh?
<Slackwarrior>
what do you mean
<mrvn_>
What you send me looks fine except the part where you now have the "add_subst"
<Slackwarrior>
can i paste here my function?
<Slackwarrior>
ehmmm i erased it
<mrvn_>
Then you have to rewrite it.
<mrvn_>
When you do better use:
<mattam>
hehe, mrvn_ is so funny sometimes
<mrvn_>
exception No_match
<mrvn_>
and "raise No_match" when no match is possible.
<mrvn_>
Otherwise return a (string, term) list
<mrvn_>
That way you allways get a simple list as return value which is easy to work with. No matching if its a No_match or a Subst all the time.
<Slackwarrior>
i dont know exceptions
<Slackwarrior>
and the prof didnt explain us
<Slackwarrior>
so it's better i use matchres
<mrvn_>
You can make a toplevel function that catches the exception and returns a matchres acordingly.
<Slackwarrior>
omg...
<Slackwarrior>
i have no idea on how exceptions work
<mrvn_>
They are easy. "excetpion No_match_exception let match_term term1 term2 = try Subst (match_term_with_exception term1 term2) with No_match_exception -> No_match
<mrvn_>
and in "match_term_with_execption" just "raise No_match_exception" when no match is possible.
<mrvn_>
There, I even throw in reversing the list.
<mrvn_>
# matchterms (b, a);;
<mrvn_>
- : matchres =
<mrvn_>
Subst [("x", Term ("h", [Var "y"; Const 0])); ("y", Term ("g", [Const 1]))]
<mellum>
Cool. ExtLib has a List.map that is tail recursive and does not reverse the list.
<Slackwarrior>
now it works
<Slackwarrior>
:)
<Slackwarrior>
can i do that without using List?
<mrvn_>
Since your Subst is declared as list: no
<Slackwarrior>
this is not good... i shouldnteven know what List is
<Slackwarrior>
whats accu
<mrvn_>
How else are you supposted to use "subst of string * term list"?
<Slackwarrior>
dunno
<mrvn_>
some variable that accumulates the result.
<Slackwarrior>
ah ok
<mrvn_>
You could call it "substs" but its kind of convention to call accumulators accu.
<Slackwarrior>
ok
<Slackwarrior>
List.rev reverses the list?
<mrvn_>
yep.
<Slackwarrior>
what if i dont wanna use it?
<mrvn_>
The List module has all kinds of usefull functions operating on lists.
<Slackwarrior>
can i write functions that replace List.rev and List.fold_left2 ?
<mrvn_>
let list_rev l = let rec loop accu = function [] -> accu | x::xs -> loop (x::accu) xs in loop [] l
<Slackwarrior>
omg
<mrvn_>
You can look at the source for module List and copy the code.
<Slackwarrior>
ah ok
<Slackwarrior>
what does List.fold_left2 do?
<mrvn_>
Look at the docs for module List.
<Slackwarrior>
ok
<Slackwarrior>
iterator on two lists?
<Slackwarrior>
what does it mean
<mrvn_>
It applies the function to the accumulator and the two top elements of the two lists repeatadly.
<Slackwarrior>
i havent understood
<Slackwarrior>
ok by the way it's time to go to bed
<Slackwarrior>
thank you very much mrvn_
<Slackwarrior>
see you tomorrow!
<mrvn_>
read up on functional programming
Slackwarrior is now known as Slackwarrior^Sle
Slackwarrior^Sle is now known as SlackwarriorSlee
SlackwarriorSlee is now known as SlackwarrSleep
<asqui>
How would I find the length of a string without using an existing function?
<mrvn_>
not at all
<mrvn_>
or only via C code.
<mrvn_>
Thats why a function exists.
<mrvn_>
or does .[i] not count as existing function?
<asqui>
What is .[i]? I meant without using an existing str_length function or whatever.
<Riastradh>
.[i] is string subscript.
<mrvn_>
let loop str_length s = let rec loop x = if (try s.[x]; true with <whatever .[] throws> -> false) then loop (x+1) else x in loop 0
<mrvn_>
Or you could binary search
<mrvn_>
Or just keep using String.length because thats O(1)
<asqui>
Ah... I'm using caml light here so it doesn't even have string subscripting!
<Riastradh>
Ewwww.
<asqui>
Well it does... in the form of some functions.
<Riastradh>
Doesn't that belong in some museum?
<Riastradh>
Museum of ancient history, that is.
<asqui>
Or university lecture course :)
<Riastradh>
Why aren't you using OCaml?
<asqui>
Probably because people's heads would explode if we used something so 'complicated'!
<Riastradh>
'Complicated'...?
<asqui>
read: Useful :)
<asqui>
We don't really need any more, the coures has been so basic that we've barely reached the limitations of caml light... and it's lasted a year with 2 hours a week...
<mrvn_>
But your missing the niceties of ocaml too.
<mrvn_>
asqui: Not using the provided length function for a string is stupid. Is that homework for the class?
<asqui>
I'm looking at past exams that ask for string length calculations, but we never covered string functions!
<asqui>
I could convert it to a stream.
<Riastradh>
Or list.
<asqui>
How do you know when you reach the end of a stream?
<asqui>
How do you convert it to a list of chars?
<Riastradh>
If it's an infinite stream you don't get to the end of it.
<asqui>
errr, yeah.... we're talking about convering a string to a stream so finite length is a given...
mattam has quit [Read error: 113 (No route to host)]
<Riastradh>
let str_to_list str = let rec loop i l = if (try str.[i]; true with (whatever .[] raises) -> false) then loop (i + 1) (str.[i] :: l) else List.rev l in loop 0 []
<mrvn_>
But instead of making a list and then counting the list you can just count in the first place.
<Riastradh>
Or just use the string length function!
<asqui>
errrr....
<asqui>
okay, nevermind...
Smerdyakov has joined #ocaml
mrvn_ is now known as mrvn
taw has joined #ocaml
<taw>
any idea how to efficiently transfer data between c++ and ocaml ?
<taw>
i must transfer some tree with lot of floats at leafs
<taw>
more or less ;)
<Smerdyakov>
Serialize and deserialize?
<mellum>
Well, you can easily access Ocaml data from C with a handful of macros...
<mellum>
Constructing Ocaml data from C is also not too hard.