Racket CSC270 Pepper major portions credited to http://learnxinyminutes.com/docs/racket/

Slides:



Advertisements
Similar presentations
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 5. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
Advertisements

Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
Lists in Lisp and Scheme a. Lists are Lisp’s fundamental data structures, but there are others – Arrays, characters, strings, etc. – Common Lisp has moved.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
1 Programming Languages and Paradigms Lisp Programming.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
Helper functions: when extra arguments are needed Consider this problem: we want a function index_items that takes a list L and gives a number to each.
מבוא מורחב - שיעור 91 Lecture 9 Lists continued: Map, Filter, Accumulate, Lists as interfaces.
Data Abstraction… The truth comes out…. What we’re doing today… Abstraction ADT: Dotted Pair ADT: List Box and Pointer List Recursion Deep List Recursion.
CS 330 Programming Languages 11 / 20 / 2007 Instructor: Michael Eckmann.
Scheme examples. Recursion Iteration is achieved via recursion Selection is achieved via COND Review the following examples to learn to think recursively.
CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
Spring 2008Programming Development Techniques 1 Topic 6 Hierarchical Data and the Closure Property Section September 2008.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Functional Programming in Scheme
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
ITEC 380 Organization of programming languages Lecture 3 – Functional Programming.
CS 152: Programming Language Paradigms February 17 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Scheme & Functional Programming. ( ) >> 64 ( ) >> 666 (* ) >> 1200 (+ (* 3 5) (- 10 6)) >> 19.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
1 Append: process  (append list1 list2) (cons 1 (append ‘(2) list2)) (cons 1 (cons 2 (append ‘() list2))) (cons 1 (cons 2 list2)) (define (append list1.
14-October-2002cse Lists © 2002 University of Washington1 Lists CSE 413, Autumn 2002 Programming Languages
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Functional Programming: Lisp MacLennan Chapter 10.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
1 Vectors, binary search, and sorting. 2 We know about lists O(n) time to get the n-th item. Consecutive cons cell are not necessarily consecutive in.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
1 Introduction to Functional Programming in Racket CS 270 Math Foundations of CS Jeremy Johnson.
CS314 – Section 5 Recitation 10
Additional Scheme examples
Functional Programming Languages
History of Computing – Lisp
CS 550 Programming Languages Jeremy Johnson
Introduction to Scheme
CSC 533: Programming Languages Spring 2017
Chapter 15 – Functional Programming Languages
Lists in Lisp and Scheme
CSC 533: Programming Languages Spring 2016
CS 270 Math Foundations of CS Jeremy Johnson
6.001 SICP Data abstractions
FP Foundations, Scheme In Text: Chapter 14.
Lecture #8 מבוא מורחב.
Modern Programming Languages Lecture 20 Fakhar Lodhi
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
topics mutable data structures
Lecture #7 מבוא מורחב.
List and list operations (continue).
Today’s topics Abstractions Procedural Data
Functional Programming: Lisp
Lecture # , , , , מבוא מורחב.
Lisp.
More Scheme CS 331.
Lists in Lisp and Scheme
Presentation transcript:

Racket CSC270 Pepper major portions credited to http://learnxinyminutes.com/docs/racket/

Screen Functions Read in a variable from the screen (read var) example : (read n) write a variable to the screen: just put the variable name final result of all functions write to the screen literal alone will write to the screen Example: "What is your name?" (define n (read )) n (string-append "hello " (symbol->string n))

String Functions Put 2 strings together: (string-append "cat" "dog") Returns "catdog" Pick out one character knowing the index (string-ref "cat" 1) Returns "a" Put a string together in printf fashion: (format " ~a are number ~a " "cats" 1) (printf " ~a are number ~a " "cats" 1) Both return "cats are number 1"

Construct a pair (small list) Make a pair (cons 3 4 ) Pull out the first element of a pair (car (cons 3 4)) Pull out the second element of a pair (cdr (cons 3 4)) Make one side of pair empty (cons null null ) Make an empty pair '() or null

Lists Define a list: linked lists of pairs with one side being the list item and the other being the rest of the list, that ends in null or () (cons 1 (cons 2 (cons 3 null))) (list 1 2 3) quote for the literal value '(1 2 3) (build-list 10 values) to get 0 to 10

Add items to a list add items to a list (cons 4 '(1 2 3 )) (append '(1 2) '(3 4))

List Functions Do the same thing to every item in the list (map add1 '(1 2 3)) gives '(2 3 4) Apply one list to another list of the same number of items (map + '(1 2 3) '(10 20 30)) extract only even (filter even? '(1 2 3 4)) gives '(2 4) count only even (count even? '(1 2 3 4)) gives 2 take the first n items (take '(1 2 3 4 ) 2) gives '(1 2 ) drop the first n items (drop '(1 2 3 4 ) 2) gives '(3 4) is it a member? (member 'dog '(cat dog rat)) gives #t first member value (first '(3 4 5)) gives 3 get number of elements (length '(3 4 5)) gives 3

Define Functions using Lists (define (addlist mylist2) (cond [ (eq? mylist2 null) 0] [ else ( + (first mylist2 ) (addlist (drop mylist2 1)))])) (define list1 (list 8 2 5)) (addlist list1) (addlist (cons 1 (cons 2 (cons 3 null))) )

Mapping Map – run the function for each item in the list (map sqrt '(4 16 25)) Apply one list to another list of the same number of items with a function taking in 2 parameters (map + '(1 2 3) '(10 20 30)) Use your own functions: (define (add3 x) (+ x 3)) (map add3 '(1 2 3))

Important Concepts Create lists Map against lists Recurse through lists until empty