Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Laboratorul de Limbaje
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==. Lisp si Scheme == Interpretor pentru Scheme (un fel de Lisp), versiune pentru Windows. Compilata din surse ale Comunitatii Haskell asa cum sunt ele prezentate intr-un faimos Wikibook. [http://www.haskell.org/sitewiki/images/2/24/Scheme-listing10.arhivagz - Download pe riscul dumneavoastra.] Atentie: au fost probleme la download-uri. 1)Cum se despacheteaza: Fisierul descarcat este numit: Scheme-listing10.arhivagz. Dati un click dreapta, alegeti redenumire si stergeti cuvantul arhiva din extensie. Ramane: Scheme-listing10.gz. Dezarhivati fisierul cu orice arhivator care admite formatul .gz - GZip. Sub Linux cu interfata grafica se poate folosi File Roller. Sub Linux cu interfata text recurgetiu la gunzip. Arhivatoarele Windows care reunosc .zip-uri pot dezarhiva si fisiere .gz. Verificati totusi. Inauntru arhivei gasiti un fisier: Scheme-listing10.exe. 2) Biblioteca minimala cu definitii de functii Scheme este data mai jos. (dupa carte :). Salvati acest text cu multe paranteze sub numele: stdlib.scm <haskell> Stdlib.scm ---------------------------------------- (define (caar pair) (car (car pair))) (define (cadr pair) (car (cdr pair))) (define (cdar pair) (cdr (car pair))) (define (cddr pair) (cdr (cdr pair))) (define (caaar pair) (car (car (car pair)))) (define (caadr pair) (car (car (cdr pair)))) (define (cadar pair) (car (cdr (car pair)))) (define (caddr pair) (car (cdr (cdr pair)))) (define (cdaar pair) (cdr (car (car pair)))) (define (cdadr pair) (cdr (car (cdr pair)))) (define (cddar pair) (cdr (cdr (car pair)))) (define (cdddr pair) (cdr (cdr (cdr pair)))) (define (caaaar pair) (car (car (car (car pair))))) (define (caaadr pair) (car (car (car (cdr pair))))) (define (caadar pair) (car (car (cdr (car pair))))) (define (caaddr pair) (car (car (cdr (cdr pair))))) (define (cadaar pair) (car (cdr (car (car pair))))) (define (cadadr pair) (car (cdr (car (cdr pair))))) (define (caddar pair) (car (cdr (cdr (car pair))))) (define (cadddr pair) (car (cdr (cdr (cdr pair))))) (define (cdaaar pair) (cdr (car (car (car pair))))) (define (cdaadr pair) (cdr (car (car (cdr pair))))) (define (cdadar pair) (cdr (car (cdr (car pair))))) (define (cdaddr pair) (cdr (car (cdr (cdr pair))))) (define (cddaar pair) (cdr (cdr (car (car pair))))) (define (cddadr pair) (cdr (cdr (car (cdr pair))))) (define (cdddar pair) (cdr (cdr (cdr (car pair))))) (define (cddddr pair) (cdr (cdr (cdr (cdr pair))))) (define (not x) (if x #f #t)) (define (null? obj) (if (eqv? obj '()) #t #f)) (define (id obj) obj) (define (flip func) (lambda (arg1 arg2) (func arg2 arg1))) (define (curry func arg1) (lambda (arg) (func arg1 arg))) (define (compose f g) (lambda (arg) (f (g arg)))) (define (foldl func accum lst) (if (null? lst) accum (foldl func (func accum (car lst)) (cdr lst)))) (define (foldr func accum lst) (if (null? lst) accum (func (car lst) (foldr func accum (cdr lst))))) (define (unfold func init pred) (if (pred init) (cons init '()) (cons init (unfold func (func init) pred)))) (define fold foldl) (define reduce fold) (define zero? (curry = 0)) (define positive? (curry < 0)) (define negative? (curry > 0)) (define (odd? num) (= (mod num 2) 1)) (define (even? num) (= (mod num 2) 0)) (define (max x . num-list) (fold (lambda (y z) (if (> y z) y z)) x num-list)) (define (min x . num-list) (fold (lambda (y z) (if (< y z) y z)) x num-list)) (define (list . objs) objs) (define (length lst) (fold (lambda (x y) (+ x 1)) 0 lst)) (define (append lst . lsts) (foldr (flip (curry foldr cons)) lst lsts)) (define (reverse lst) (fold (flip cons) '() lst)) (define (mem-helper pred op) (lambda (acc next) (if (and (not acc) (pred (op next))) next acc))) (define (memq obj lst) (fold (mem-helper (curry eq? obj) id) #f lst)) (define (memv obj lst) (fold (mem-helper (curry eqv? obj) id) #f lst)) (define (member obj lst) (fold (mem-helper (curry equal? obj) id) #f lst)) (define (assq obj alist) (fold (mem-helper (curry eq? obj) car) #f alist)) (define (assv obj alist) (fold (mem-helper (curry eqv? obj) car) #f alist)) (define (assoc obj alist) (fold (mem-helper (curry equal? obj) car) #f alist)) (define (map func lst) (foldr (lambda (x y) (cons (func x) y)) '() lst)) (define (filter pred lst) (foldr (lambda (x y) (if (pred x) (cons x y) y)) '() lst)) (define (sum . lst) (fold + 0 lst)) (define (product . lst) (fold * 1 lst)) (define (and . lst) (fold && #t lst)) (define (or . lst) (fold || #f lst)) (define (any? pred . lst) (apply or (map pred lst))) (define (every? pred . lst) (apply and (map pred lst))) ---------------------------------------------------------------- </haskell> Observati ca trecerea de la Lisp la Scheme nu este grea (defun devine define samd) iar trecerea de la Scheme la Haskell nu este imposibila. Multe cuvinte din Scheme se folosesc si in Haskell (le aveti marcate cu verde). Daca dati click pe le obtineti Help-ul functiilor Haskell cu acelasi nume, nu al celor Scheme. De acord, deosebirile nu sunt mari. Urmeaza sa mai explic cate ceva...Reveniti.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width