Semplificati la vita..

Io mi chiedo perchè la gente si diverta a fare gare di oscuramento del codice in C, Perl, Python o Java quando esiste OCaml

Codice:
let rec lmn l = let rec lm l1 l2 = match l1, l2 with [], [] -> []
| _, [] -> l1 | [], _ -> l2 | x::y, _ -> x :: (lm y l2) in match l
with [] -> [] | [x] -> x | x::y -> lm x (lmn y);;

Risultato: fare il merge di due liste
# lmn [1;2;3];[4;5];[6;7];[8;9;10]];;
- : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]

Quanto mi piace il laboratorio di Metodi 1 :)

8 Comments

  1. il bello è che la stessa cosa si può fare con la funzione concat del modulo List

    # List.concat [[4;6];[5;9];[1;2;3]];;
    - : int list = [4; 6; 5; 9; 1; 2; 3]

    :D

    Posted October 11, 2005 at 8:12 pm | Permalink
  2. em

    Lol. :)

    $ python
    >>> [1,2,3] + [4,5] + [6,7] + [8,9,10]
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    Posted October 11, 2005 at 11:30 pm | Permalink
  3. comunque la mia soluzione senza barare è questa guiduzzo

    let rec append (l:int list list)=
    match l with
    [] -> []
    |x -> x
    |x::rest -> x @ append(rest);;

    forse è un po più umana :D

    Posted October 11, 2005 at 11:59 pm | Permalink
  4. Anonymous

    semmai:

    let rec append (l:int list list)=
    match l with
    [] -> []
    |[x] -> x
    |x::rest -> x @ append(rest);;

    comunque non vale! non ricordavo piu' l'uso dell'operatore chiocciolina!! se no la mia si riduceva drasticamente, x' in realtà la mia funzione è:
    let rec lmn l =
    let rec lm l1 l2 =
    match l1, l2 with
    [], [] -> []
    | _, [] -> l1
    | [], _ -> l2
    | x::y, _ -> x :: (lm y l2)
    in match l with
    [] -> []
    | [x] -> x
    | x::y -> lm x (lmn y);;

    dove appunto la lm fa' quello che avrei potuto fare con la @ :/

    Posted October 12, 2005 at 12:20 am | Permalink
  5. Anonymous

    X Ema:

    dopo che davis ha scoperto la @ possiamo fare anche noi cosi':

    # [3;4] @ [5;6] @ [7;8];;
    - : int list = [3; 4; 5; 6; 7; 8]

    xo' non è ricorsivo, obfuscato, con pattern matching, QUINDI NON FA' FIGO :D

    Posted October 12, 2005 at 12:28 am | Permalink
  6. ehy tha, sono pedrag.
    è da un po' che non ci si sente ;)
    procede tutto bene?

    un saluto

    Posted October 12, 2005 at 1:40 am | Permalink
  7. Ma perche non uscite un pò più spesso di casa, e non andate magari a puttane che vi farebbe bene. invece di scrivere ste cagate?

    Posted October 12, 2005 at 10:35 pm | Permalink
  8. io ho la tracheobronchite!

    Posted October 15, 2005 at 12:25 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*