Nihilistic programming

Status
Not open for further replies.

lensam69

Ars Scholae Palatinae
746
Originally posted by lensam69:
Three months ago i implemented a fuzzy logic expression evaluator in CAML. I'll see if i can find it, but trust me: You don't want to see it...


And here it is:

This is supposed to recognize a fuzzy Logic expression.


code:<HR>
Code:
(********************************************************)



let rec ident_formula = function



 [<'NOT ; formula>] -> Negada (ident_formula formula)



|[<'LPAR; expr>] -> ident_par expr



|[<'EXISTS; 'SIMBOLO var; 'IN; 'SIMBOLO set; form >]-> Exists (var, set, (ident_formula form))



|[<'FORALL; 'SIMBOLO var; 'IN; 'SIMBOLO set; form >]-> Forall (var, set, (ident_formula form))



 



|[<'SIMBOLO simb; expr>] -> (Lit (ident_literal simb expr))



(********************************************************)



and



(********************************************************)



obt_fset str = function



 [<'RPAR; 'FIN>] -> ({x1=(stream_next str); x2=(stream_next str); x3=(stream_next str); x4=(stream_next str);})



|[<'LPAR; st2>] -> obt_fset str st2



|[<'INF; st2>] -> obt_fset [<'"T"; str >] st2



|[<'FLOAT flt; st2>] -> obt_fset [< '(string_of_float flt); str>] st2



|[<'COMA; st2>] -> obt_fset str st2



|[<>] -> raise (Failure "Error: Fuzzy set mal declarado")



(********************************************************)



and



(********************************************************)



setToString = function



 [<'RCOR>] -> ""



|[<'FLOAT flt; str>] -> (string_of_float flt)^(setToString str)



|[<'COMA; str>] -> " "^(setToString str)



|[<'SIMBOLO var; str>] -> var^(setToString str)



|[<>] -> raise (Failure "Error!!! Conjunto mal declarado") 



(********************************************************)



and



(********************************************************)



ident_exists nombre st st2= match st2 with



[<'RCOR; st3>] -> Exists (nombre ,(setToString [<st; 'RCOR>]) ,(ident_formula st3))



|[<'x>] -> ident_exists nombre [<st; 'x>] st2



|[<>] -> raise (Failure "Error en cuantificador!!!")                  



(********************************************************)



and



(********************************************************)



ident_forall nombre st st2= match st2 with



[<'RCOR; st3>] -> Forall (nombre ,(setToString [<st; 'RCOR>]) ,(ident_formula st3))



|[<'x>] -> ident_forall nombre [<st; 'x>] st2



|[<>] -> raise (Failure "Error en cuantificador!!!")   



(********************************************************)



and



(********************************************************)



ident_literal simb = function



 [<'LPAR; st>] -> (match st with 



                   [<'SIMBOLO var; 'RPAR>] ->  Predicado_var (simb, (var))



                  |[<'FLOAT flt; 'RPAR >] -> Predicado_ctt (simb, (flt))



                  |[<>] -> raise (Failure "Error: No se pudo identificar literal")



                 )



|[<'SIMBOLO lit2; st>]  -> (Modificador (simb, (ident_literal lit2 st)))



(********************************************************)



and



(********************************************************)



parse_logic par_left st st2= match st2 with



  [<'AND>] -> (if (par_left = 0) then (Y (ident_formula st, ident_formula st2)) 



                                 else (parse_logic par_left [<st; 'AND>] st2)



              )



              



 |[<'OR>] -> (if (par_left = 0) then (O (ident_formula st, ident_formula st2)) 



                                 else (parse_logic par_left [<st; 'OR>] st2)



             )



 



 |[<'LPAR; str>] -> (parse_logic (par_left + 1) [<st; 'LPAR>] st2)



 |[<'RPAR; str>] -> (parse_logic (par_left - 1) [<st; 'RPAR>] st2)



 



 



 



 |[<'x>] -> parse_logic par_left [<st ; 'x>] st2



 |[<>]-> raise (Failure "Error:  Instruccion incorrecta (Parsing for logic) ;")



        



                                                                                                                                      



(********************************************************)



and



(********************************************************)



ident_par  = function 



[< '(SIMBOLO term1);st1>] -> 



     (match st1 with [<'(SIMBOLO comparator);st2>] -> 



                        (match st2 with [<'(SIMBOLO term2) ; st3>] ->



                                                           (match  st3 with 



                                                            [<'RPAR >] -> Comparar ((Variable term1), comparator, (Variable term2))



                                                           |[<>] -> let str_aux = [<'(SIMBOLO term1);'(SIMBOLO comparator);'(SIMBOLO term2); st3>] in 



                                                           



                                                                    (parse_logic 0 [<>] str_aux)) 



                                                                         



                                                                      



                                                                    



                                         |[<'(FLOAT flt2); st3>] ->



                                                           match  st3 with 



                                                            [<'RPAR >] -> Comparar ((Variable term1), comparator, (Valor flt2))



                                                           |[<>] -> raise (Failure "Error analizando un comprador")



                                         |[<>] -> let str_aux = [<'(SIMBOLO term1);'(SIMBOLO comparator); st2>] in 



                                                           



                                                 (parse_logic 0 [<>] str_aux) )



                                                  



                                                



                   |[<>] -> (let st_aux = [<'(SIMBOLO term1); st1>] in



                            parse_logic 0 [<>] st_aux)



     )



|[<'(FLOAT flt1); st1>] ->



    ( match st1 with [<'(SIMBOLO comparator); st2>] ->



                        match st2 with [<'SIMBOLO term2;'RPAR>] -> Comparar ((Valor flt1), comparator, (Variable term2))



                                      |[<'FLOAT flt2; 'RPAR>] ->  Comparar ((Valor flt1), comparator, (Valor flt2))



                                      |[<>] -> raise (Failure "Error analizando un comparador")



                                      



                   |[<>] -> raise (Failure "Error analizando un comparador")



)



|[<st0>] -> parse_logic 0 [<>] st0;;



(********************************************)
 
yes, thats cobol, man do i hate that language. I got a 100 on that program, but just that fact that its COBOL!!! I REALLY hate that language. It makes me feel retarded whenever i have to code in it. I think that each time i design a data division, i get dumber...

-----------
Crackez

Edit: euzeka, thanks for the compliment man, it's only my third program this semester in that class... I didn't think you could make any cobol look nice...
 
Edit: euzeka, thanks for the compliment man, it's only my third program this semester in that class... I didn't think you could make any cobol look nice...
Well, COBOL being nice is relative to what COBOL could be when left unchecked :p You just seem to be missing a few blank lines and comments between the paragraphs. Otherwise, you have nice identation, and seem to have split the code in functional blocks.

Disclaimer: I've only written 4 COBOL programs in my life, and I intend for things to stay that way. Sad thing is, the COBOL class was removed the year after I entered University :mad: I was a year too early I guess.
 

pelican

Wise, Aged Ars Veteran
184
Hows that for lack of morals?

I am thoroughly impressed.

I was referring more to the nihilism of the programmer, not the code Crackez. Exactly.

I just wanted to drop a line back into this thread to say it's really making me feel a *lot* better about being frustrated doing a code read of my own code, and continually going what the hell was I thinking when I did that? Why didn't a write an object or a *gasp* function? Where the heck are the comments??? ;)

--pelican
 

et82

Wise, Aged Ars Veteran
154
For real nihilistic programming you have to go back to the roots of all programming:

Assembler

And for real obscure Assembler you have to use ARM assembler like this one:

code:<HR>
Code:
alpha     STMED   r13!, {r2, r3, r4, r14}
	    MOV     r2, #65	
	    MOV     r3, #1		
	    ADD     r5, r5, #1
loopalp   LDRB    r1, [r0, +r5]
	    CMP     r1, #90	
	    BLGT    nextlet	
	    CMP     r1, #90		
	    BGT     Exit		
	    CMP     r1, r2			
	    ADDEQ   r3, r3, #1	
	    BLGT    nextlet	
	    ADD     r5, r5, #1	
	    B       loopalp	
Exit      LDMED   r13!, {r2, r3, r4, r14}
	    MOV     PC, r14

hexout    STMED   r13!, {r0, r2, r3} 
	    MOV     r2, #8
LOOP      MOV     r0, r1, LSR #28
	    CMP     r0, #9
	    ADDGT   r0, r0, #'A'-10
	    ADDLE   r0, r0, #'0'
	    SWI     SWI_WriteC
	    MOV     r1, r1, LSL #4
	    SUBS    r2, r2, #1
	    BNE     LOOP
	    LDMED   r13!, {r0, r2, r3}
	    MOV     pc, r14
 

Magus`

Ars Legatus Legionis
30,136
Subscriptor++
Not sure if this counts, but a friend of mine wrote it, and I can't make heads or tails of it :D

code:<HR>
Code:
#!/usr/bin/perl
use strict;
open (PROC,"/proc/net/tcp");
while (<PROC> ) {
	s/([0-9A-F]{8})/xlateaddr($1)/eg;
	s/:([0-9A-F]{4})/":" . xlatehex($1)/eg;
	print;
}
sub xlateaddr { join ".", map hex , reverse shift =~ m/[0-9A-F]{2}/g;}
sub xlatehex { sprintf "%d", hex shift; }
 
Status
Not open for further replies.