1 / 20

Praktikum Bahasa Pemrograman Pertemuan #1

Praktikum Bahasa Pemrograman Pertemuan #1. Program Sarjana Alih Jenis Departemen Ilmu Komputer Institut Pertanian Bogor 2011. Scheme. Berkembang di Lab Artificial Intelligent (AI) MIT oleh Guy L. Steele dan Gerald J. Sussman tahun 1975 Merupakan bahasa pemrograman fungsional

cato
Télécharger la présentation

Praktikum Bahasa Pemrograman Pertemuan #1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Praktikum Bahasa PemrogramanPertemuan #1 Program Sarjana Alih Jenis Departemen Ilmu Komputer Institut Pertanian Bogor 2011

  2. Scheme • Berkembang di Lab Artificial Intelligent (AI) MIT oleh Guy L. Steele dan Gerald J. Sussman tahun 1975 • Merupakan bahasa pemrograman fungsional • Perkembangan relatif lambat dengan mengutamakan kehandalan fitur • Digunakan pada skala akademik sampai pada tingkat industri • Sintaks sederhana dengan notasi prefiks (operator di depan diikuti dengan operand) totoharyanto.staff.ipb.ac.id

  3. Memulai Scheme • Cara terbaik untuk mempelajari bahasa ini adalah: • Dengan banyak bermain dan mencoba ide-ide untuk memodifikasi hal-hal baru yang belum pernah tersentuh • Selama menjadi mahasiswa, cobalah ide-ide kreatif tersebut • Mari Belajar ! totoharyanto.staff.ipb.ac.id

  4. Memulai dengan Scheme Pilih bahasa : Language totoharyanto.staff.ipb.ac.id

  5. Language totoharyanto.staff.ipb.ac.id

  6. Sintaks >(+ 2 3 4 ) ; komentar prefiks operator >(*(* 2 4) 5); ? >(/ (* 5 20) 4); ? • (modulo 10 3); ? Cobalah dengan contoh lainnya ! Pelajaran: Sintaks pada Scheme dengan notasi prefiks totoharyanto.staff.ipb.ac.id

  7. Ekspresi • Scheme mengenal dua jenis ekspresi • 1. Ekspresi primitif • 2. Ekspresi derivatif (turunan) Ekpresi primitif : ekpresi standar dalam bahasa pemrograman seperti referensi variabel, ekpresi literal, penugasan, prosedur dan pemanggilan prosedur Ekspresi turunan: ekspresi yang dinyatakan dalam bentuk ekspresi lain dan tidak dinyatakan secara langsung totoharyanto.staff.ipb.ac.id

  8. Ekspresi Primitif • Referensi Variabel > (define a 10) > (define b 20) > (+ a b) • Ekspresi literal ekpresi yang menggunakan quote atau ‘ > (quote a) > (quote ab) > ‘a > ‘ab • Bilangan, string, karakter, dan boolen tidak perlu dikutip karena menilai dirinya sendiri totoharyanto.staff.ipb.ac.id

  9. Ekspresi Primitif • Penugasan / assignment: Menggunakan perintah set! > (set! a 9) > a • Ekspresi kondisi primitif (menggunakan if) > (set! a 20) a > (if (> a 25) 'lulus 'tidak) totoharyanto.staff.ipb.ac.id

  10. Ekspresi Primitif • Prosedur : menggunakan lambda dan ditutup dengan > ((lambda (x) (* 2 x)) 5) • Prosedur dengan define > (define (kuadrat x)(* x x)) > (kuadrat 20) Apa perbedaannya ? totoharyanto.staff.ipb.ac.id

  11. Ekspresi Turunan • Ekpresi kondisi cond dengan nested if (define a 10) (if (< a 10)a (if (< a 20) (* a a) 0)) ====================================== (cond ((< a 10) a) ((< a 20) (* a a)) (else 0)) totoharyanto.staff.ipb.ac.id

  12. Ekspresi Turunan • Ekspresi let dapat dituliskan dengan lambda (let ((a 20) (b 30)) (* a b)) Ekuivalen dengan ((lambda (a b) (* a b)) 20 30) totoharyanto.staff.ipb.ac.id

  13. Contoh • Prosedur Menghitung Bilangan Fibonaci (define fib (lambda (n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fib (- n 1)) (fib (- n 2))))))) totoharyanto.staff.ipb.ac.id

  14. Let, let* and letrec • Digunakan untuk menciptakan variabel lokal • Perbedaan terdapat pada letak/region untuk menetapkan variabel binding (pengikatan variabel) • Let: Bentuk umum (let ((var1 exp1) (var2 exp2) . . . (varn expn)) body) • Contoh : >(let ((x 2) (y 10)) (+ x y)) 12 s((lambda (x y) (+ x y)) 2 10) totoharyanto.staff.ipb.ac.id

  15. Contoh penggunaan Let (define x 10) (+ (let ((x 5)) (* x (+ x 2))) x) Berapa keluarannya ? The body of the let expression is the expression (* x (+ x 2)) ============================================ (define x 10)  (let ((x 5) (y (* x 2))) (+ x y)) totoharyanto.staff.ipb.ac.id

  16. Let* Cobalah listing program berikut ini ! (define x 10) (let* ((x 5)(y (* x 2))) (+ x y)) Berapa outputnya ? Bandingkan dengan (define x 10) (+(let* ((x 5)(y (* x 2))) (+ x y)) x) totoharyanto.staff.ipb.ac.id

  17. Letrec • Digunakan untuk kebutuhan proses rekursif • Lakukan proses iterasi berikut (define (factorial n) (define (iter product counter) (if (> counter n) product (iter (* counter product) (+ counter 1)))) (iter 1 1)) totoharyanto.staff.ipb.ac.id

  18. Faktorial menggunakan Letrec ;; The procedure factorial rewritten using letrec (define factorial (lambda (n) (letrec ((iter (lambda (product counter) (if (> counter n) product (iter (* counter product) (+ counter 1)))))) (iter 1 1))) totoharyanto.staff.ipb.ac.id

  19. Selesai Bersemangatlah terhadap yang bermanfaat bagimu. Mintalah pertolongan kepada Alloh Janganlah Engakau Bersedih totoharyanto.staff.ipb.ac.id

  20. Wassalamu’alaikum totoharyanto.staff.ipb.ac.id

More Related