<Mr_Awesome>
anyone know a quick way to get the last element of a list?
<TSC>
reverse it and then take the head
<Mr_Awesome>
ah, thanks
<Mr_Awesome>
hmm, would getting the length and indexing that minus one be faster?
<TSC>
I doubt it, but you can try
<TSC>
Both take linear time
<Mr_Awesome>
right, i guess it doesnt really matter
mrsolo_ has quit [Remote closed the connection]
<gonnet>
(what about the memory cost ?)
<gonnet>
if you first have to make a (reverse) copy, and then only take the first element, it will be worse than simply reading until the last element i guess
<TSC>
I guess so too
<zmdkrbou>
anyway, you shouldn't have to take the last element of a list
<gonnet>
indeed, somewhat strange for a list
<gonnet>
perhaps the algorithm can be rewritten if those are the only access that are done ?
<TSC>
I had to do it recently, because I wanted the minimum and maximum values in a sorted list
<zmdkrbou>
yes, that's not meant for it, either you take the head or do a recursion on it, but taking the last element ...
<zmdkrbou>
mmmh TSC, there is List.sort :)
<TSC>
Yes, the list was already sorted
<TSC>
I wanted the two ends
<zmdkrbou>
oh, misread
<gonnet>
n log n gg zmdkrbou :)
<TSC>
(:
<Mr_Awesome>
well, i have a list of ints, and if my current int sequentially follows the last int in the list, i want to append it to the end
<gonnet>
seems hard to avoid this then !
<zmdkrbou>
TSC: did you sort it yourself ?
<gonnet>
i guess not :)
<gonnet>
would be a strange algorithme
<gonnet>
-e
<Mr_Awesome>
im searching for a straight in a poker hand
<TSC>
zmdkrbou: No, the list was maintained in sorted order (it was the implementation of a set)
<zmdkrbou>
ok
<Mr_Awesome>
i suppose i could sort the list first, then step through and append only in the beginning
<gonnet>
well, simplest ... go into the list ..
<zmdkrbou>
Mr_Awesome: so your list is a poker hand ?
<gonnet>
anyway it seems that you won't get anything better than n ops
<gonnet>
n+1 seems not to hard to code
<zmdkrbou>
if it's a poker hand, the list is soooooooo small that you really don't care about getting it reversed or what ...
<Mr_Awesome>
zmdkrbou: is that a question?
<zmdkrbou>
nope
<zmdkrbou>
is your list fixed in length ?
<Mr_Awesome>
no
<zmdkrbou>
strange poker hand :p
<Mr_Awesome>
range of 2-7
<zmdkrbou>
huhu
<gonnet>
not too long then :)
<zmdkrbou>
so it's terribly small
<Mr_Awesome>
think texas holdem or seven card stud
<zmdkrbou>
first thing, you don't need to think about complexity with a list of max. 7 elements
<Mr_Awesome>
yeah i know
<gonnet>
it is all O(1) :)
<Mr_Awesome>
im thinking about conciseness in code
<zmdkrbou>
and you should use { card1 : bla ; card2 : bla ; etc. }
<Mr_Awesome>
i should use a record? for what?
<zmdkrbou>
(or not ... would be a bit strange to search in this record)
<zmdkrbou>
because you don't need a variable length structure
<Mr_Awesome>
but i do, like i said a range of 2-7
<zmdkrbou>
you can take 7 and have a fake card representation
<Mr_Awesome>
wouldnt a list be easier to work with though?
<zmdkrbou>
yes
<Mr_Awesome>
youre not very convincing ;)
<zmdkrbou>
the simplest way is using a list and not thinking of complexity
<Mr_Awesome>
right, im just trying to find a nice straightforward concise method
<zmdkrbou>
because list are easy to work with, and with 7 elements you don't care at all what you do with it
<Mr_Awesome>
right now, the method is kind of bloated
<zmdkrbou>
List.hd (List.rev l) is ok
<Mr_Awesome>
yeah, i guess so
<TSC>
Or use "let last l = List.hd (List.rev l)", then it's even shorter!
<Mr_Awesome>
i used "let last = List.hd (List.rev l)"
<Mr_Awesome>
since im only doing it once
b00t has joined #ocaml
b00t has quit [Remote closed the connection]
b00t has joined #ocaml
<Mr_Awesome>
anyone know a good way to get the first five elements of a list, without resorting to making a recursive function?
marcelino has joined #ocaml
marcelino has quit ["Ex-Chat"]
b00t has quit [Client Quit]
b00t has joined #ocaml
<Smerdy>
Mr_Awesome, it's easy with pattern-matching.
Smerdy is now known as Smerdyakov
<Mr_Awesome>
too late, i already wrote a list_sub function lol
jcreigh has quit ["Cuius rei demonstrationem mirabilem sane detexi. Hanc marginis exiguitas non caperet."]
Mr_Awesome has left #ocaml []
shekmalhen has joined #ocaml
shawn__ has joined #ocaml
_velco has joined #ocaml
shekmalhen has quit ["dodo"]
shawn__ has quit ["This computer has gone to sleep"]
b00t has quit [Read error: 110 (Connection timed out)]
_velco has quit ["I'm outta here ..."]
Snark has joined #ocaml
pango has joined #ocaml
smimou has joined #ocaml
<pango>
<gonnet> it is all O(1) :)
<pango>
O() notation is about asymptotical limit, so it makes no sense using it in this case, on bounded arguments
shawn__ has joined #ocaml
love-pingoo has joined #ocaml
Axioplase has joined #ocaml
<Axioplase>
Hi !
<Axioplase>
I have a weird "bug..."
<Axioplase>
in my file, I have "let ti = Unix.gmtime(Unix.gettimeofday()) in [blablabla]"
<Axioplase>
and when I compile I get two different errors, according to what [blablabla] is.
<smimou>
what are those errors?
<Axioplase>
if it's the empty string, then the error is Error while linking emit.cmo: Reference to undefined global `Unix'
<Axioplase>
if it's something using ti (to print the fields) I get : Unbound record field label tm_year
<Axioplase>
(and so on if i remove the year label)
<pango>
record fields are bound to their module namespace (Unix.tm_year, ...)
<pango>
(record field names, I mean)
<pango>
now, you should get undefined global `Unix' in all cases ;)
<love-pingoo>
with the empty string, the compiler sees no error before linking, with your other expr an error occurs during compilation (did you mean Unix.tm_year ?).. that's not surprising to get different errors in such cases
<Axioplase>
haaa.. I get it...
<Axioplase>
ok thanks...
<Axioplase>
Weird I find, but ogical indeed...
love-pingoo has quit ["Connection reset by pear"]
<pango>
for your linking problem, you need to link against unix.cma (bytecode) or unix.cmxa (native)
<Axioplase>
yep. That's what I m trying to do... (it s not my Makefile, and it's quite obfuscated for me ^^)
pango has quit ["bbl"]
slipstream-- has joined #ocaml
pango has joined #ocaml
slipstream has quit [Read error: 110 (Connection timed out)]
Wild_Cat has joined #ocaml
Wild_Cat has quit [Client Quit]
shawn__ has quit [Read error: 110 (Connection timed out)]
shawn__ has joined #ocaml
smimou has quit ["bli"]
love-pingoo has joined #ocaml
Wild_Cat has joined #ocaml
finelemo1 has joined #ocaml
Axioplase has quit ["kore kara tabe ni iku ! (ca vous la coupe hein, bande de moules !)"]
sp00k has joined #ocaml
sp00k has left #ocaml []
finelemon has quit [Read error: 110 (Connection timed out)]
joshcryer has quit [Read error: 104 (Connection reset by peer)]
b00t has joined #ocaml
|Lupin| has joined #ocaml
<|Lupin|>
Hello, all.
<|Lupin|>
This is an OCaml/Windows question
<zmdkrbou>
lo |Lupin|
<|Lupin|>
We use a Cygwin version of OCaml
<|Lupin|>
and it seems that dynamicloading isnotSupported
<|Lupin|>
Is that right, and whatshould one do to avoid this obstacle, please ?
<|Lupin|>
lo zmdkrbou
<ppsmimou>
hi |Lupin|
<|Lupin|>
hi ppsmimou
<|Lupin|>
For instance
<|Lupin|>
#load "unix.cma";;
<|Lupin|>
doesn't work on Windows...
<ppsmimou>
my only advice would be to use putty and do an ssh on a real box