Racket-Expr-Decl.Pptx

Total Page:16

File Type:pdf, Size:1020Kb

Racket-Expr-Decl.Pptx LISP: designed by John McCarthy, 1958 published 1960 Introduc)on to Racket, a dialect of LISP: Expressions and Declara)ons CS251 Programming Languages Spring 2019, Lyn Turbak Department of Computer Science Wellesley College These slides build on Ben Wood’s Fall ‘15 slides Expr/decl 2 LISP: implemented by Steve Russell, LISP: LISt Processing early 1960s • McCarthy, MIT arNficial intelligence, 1950s-60s – Advice Taker: represent logic as data, not just program Emacs: M-x doctor • Needed a language for: – Symbolic computaNon i.e., not just number crunching – Programming with logic – ArNficial intelligence – Experimental programming • So make one! Expr/decl 3 Expr/decl 4 Scheme • Gerald Jay Sussman and Guy Lewis Steele (mid 1970s) • Grandchild of LISP (variant of Scheme) • Lexically-scoped dialect of LISP – Some changes/improvements, quite similar that arose from trying to make • Developed by the PLT group an “actor” language. (haps://racket-lang.org/people.html), the same folks who • Described in amazing “Lambda the UlNmate” created DrJava. papers (hap://library.readscheme.org/page1.html) • Why study Racket in CS251? – Lambda the UlNmate PL blog inspired by these: – Clean slate, unfamiliar hap://lambda-the-ulNmate.org – • Led to Structure and InterpretaNon Careful study of PL foundaNons (“PL mindset”) of Computer Programs (SICP) and – FuncNonal programming paradigm MIT 6.001 (haps://mitpress.mit.edu/sicp/) • Emphasis on funcNons and their composiNon • Immutable data (lists) – Beauty of minimalism – Observe design constraints/historical context Expr/decl 5 Expr/decl 6 Expressions, Values, and DeclaraNons Values • Values are expressions that cannot be evaluated • EnNre language: these three things further. • Syntax: • Expressions have evalua6on rules: – Numbers: 251, 240, 301 – How to determine the value denoted by an expression. – Booleans: #t, #f – There are more values we will meet soon • For each structure we add to the language: (strings, symbols, lists, funcNons, …) – What is its syntax? How is it wriaen? • EvaluaNon rule: – What is its evalua)on rule? How is it evaluated to a – Values evaluate to themselves. value (expression that cannot be evaluated further)? Expr/decl 7 Expr/decl 8 AddiNon expression: syntax AddiNon expression: evaluaNon Adds two numbers together. Syntax: (+ E1 E2) Note recursive Syntax: (+ E1 E2) Every parenthesis required; none may be omiaed. EvaluaNon rule: structure! E1 and E2 stand in for any expression. 1. Evaluate E1 to a value V1 Note prefix notaNon. Note recursive 2. Evaluate E2 to a value V2 Examples: structure! 3. Return the arithmeNc sum of V1 + V2. (+ 251 240) (+ (+ 251 240) 301) (+ #t 251) Not quite! Expr/decl 9 Expr/decl 10 AddiNon: dynamic type checking EvaluaNon AsserNons Formalize EvaluaNon Syntax: (+ E1 E2) The evalua)on asser)on notaNon E ↓ V means S)ll not quite! ``E evaluates to V ’’. EvaluaNon rule: More later … Our evaluaNon rules so far: 1. evaluate E1 to a value V1 • value rule: V ↓ V (where V is a number or boolean) 2. Evaluate E2 to a value V2 • addi6on rule: 3. If V1 and V2 are both numbers then if E1 ↓ V1 and E2 ↓ V2 return the arithmeNc sum of V1 + V2. and V1 and V2 are both numbers 4. Otherwise, a type error occurs. and V is the sum of V1 and V2 then (+ E1 E2) ↓ V Dynamic type-checking Expr/decl 11 Expr/decl 12 EvaluaNon DerivaNon in English More Compact DerivaNon NotaNon An evalua)on deriva)on is a ``proof ’’ that an expression V ↓ V [value rule] E1 ↓ V1 evaluates to a value using the evaluaNon rules. E2 ↓ V2 whereVis a value [addiNon rule] ↓ (+ 3 (+ 5 4)) 12 by the addiNon rule because: (number, boolean, etc.) (+ E1 E2) ↓ V • 3 ↓ 3 by the value rule side condiNons of rules Where V1 and V2 are numbers and • (+ 5 4) ↓ 9 by the addiNon rule because: V is the sum of V1 and V2. – 5 ↓ 5 by the value rule ↓ [value] – ↓ by the value rule 3 3 4 4 – 5 and 4 are both numbers 5 ↓ 5 [value] – 9 is the sum of 5 and 4 4 ↓ 4 [value] [addiNon] • 3 and 9 are both numbers (+ 5 4) ↓ 9 [addiNon] • 12 is the sum of 3 and 9 (+ 3 (+ 5 4)) ↓ 12 Expr/decl 13 Expr/decl 14 Errors Are Modeled by “Stuck” DerivaNons SyntacNc Sugar for AddiNon The addiNon operator + can take any number of operands. How to evaluate How to evaluate • For now, treat (+ E1 E2 … En)as (+ (+ E1 E2) … En) (+ #t (+ 5 4))? (+ (+ 1 2) (+ 5 #f))? E.g., treat (+ 7 2 -5 8) as (+ (+ (+ 7 2) -5) 8) #t ↓ #t [value] 1 ↓ 1 [value] • Treat (+ E)as E (or say if E ↓ V then (+ E) ↓ V) 5 ↓ 5 [value] 2 ↓ 2 [value] • Treat (+) as 0 (or say (+)↓ 0 ) 4 ↓ 4 [value] (+ 1 2) ↓ 3 [addiNon] [addiNon] • (+ 5 4) ↓ 9 5 ↓ 5 [value] This approach is known as syntac)c sugar: introduce new syntacNc forms that “desugar” into exisNng ones. Stuck here. Can’t apply #f ↓ #f [value] (addiNon) rule because • In this case, an alternaNve approach would be to introduce #t is not a number in Stuck here. Can’t apply (addiNon) rule because more complex evaluaNon rules when + has a number of (+ #t 9) #f is not a number in arguments different from 2. (+ 5 #f) Expr/decl 15 Expr/decl 16 Other ArithmeNc Operators RelaNon Operators Similar syntax and evaluaNon for The following relaNonal operators on numbers return - * / quotient remainder min max booleans: < <= = >= > except: • Second argument of /, quotient, remainder must be nonzero For example: • Result of / is a raNonal number (fracNon) when both values are integers. (It is a floaNng point number if at least one value ↓ is a float.) E1 V1 E2 ↓ V2 • quotient and remainder take exactly two arguments; [less than] anything else is an error. (< E1 E2) ↓ V • (- E) is treated as (- 0 E) • (/ E) is treated as (/ 1 E) Where V1 and V2 are numbers and V is #t if V1 is less than V2 • (min E) and (max E) treated as E or #f if V1 is not less than V2 • (*) evaluates to 1. • (/), (-), (min) , (max) are errors (i.e., stuck) Expr/decl 17 Expr/decl 18 CondiNonal (if) expressions DerivaNon-style rules for CondiNonals Syntax: (if Etest Ethen Eelse) Etest ↓ Vtest Eelse is not Ethen ↓ Vthen [if nonfalse] evaluated! EvaluaNon rule: (if Etest Ethen Eelse) ↓ Vthen 1. Evaluate Etest to a value Vtest. Where Vtest is not #f 2. If Vtest is not the value #f then return the result of evaluaNng Ethen Etest ↓ #f otherwise Eelse ↓ Velse Ethen is not return the result of evaluaNng Eelse [if false] (if Etest Ethen Eelse) ↓ Velse evaluated! Expr/decl 19 Expr/decl 20 Your turn Expressions vs. statements Use evaluaNon derivaNons to evaluate the CondiNonal expressions can go anywhere an following expressions expression is expected: (if (< 8 2) (+ #f 5) (+ 3 4)) (+ 4 (* (if (< 9 (- 251 240)) 2 3) 5)) (if (if (< 1 2) (> 4 3) (> 5 6)) (if (+ 1 2) (- 3 7) (/ 9 0)) (+ 7 8) (* 9 10) (+ (if (< 1 2) (* 3 4) (/ 5 6)) 7) Note: if is an expression, not a statement. Do (+ (if 1 2 3) #t) other languages you know have condiNonal expressions in addiNon to condiNonal statements? (Many do! Java, JavaScript, Python, …) Expr/decl 21 Expr/decl 22 Design choice in condiNonal semanNcs CondiNonal expressions: careful! In the [if nonfalse] rule, Vtest is not required to be a boolean! Unlike earlier expressions, not all Etest ↓ Vtest Ethen ↓ Vthen subexpressions of if expressions are evaluated! [if nonfalse] (if Etest Ethen Eelse) ↓ Vthen Where Vtest is not #f (if (> 251 240) 251 (/ 251 0)) This is a design choice for the language designer. What would happen if we replace the above rule by Etest ↓ #t (if #f (+ #t 240) 251) ↓ Ethen Vthen [if true] (if Etest Ethen Eelse) ↓ Vthen This design choice is related to noNons of “truthiness” and Expr/decl 23 “falsiness” that you will explore in PS2. Expr/decl 24 Environments: MoNvaNon Environments: DefiniNon Want to be able to name values so can refer to • An environment is a sequence of bindings that them later by name. E.g.; associate idenNfiers (variable names) with values. – Concrete example: (define x (+ 1 2)) num ⟼ 17, absoluteZero ⟼ -273, true ⟼#t – Abstract Example (use Id to range over idenNfiers = names): (define y (* 4 x)) Id1 ⟼ V1, Id2 ⟼ V2, …, Idn ⟼ Vn – Empty environment: ∅ (define diff (- y x)) • An environment serves as a context for evaluaNng (define test (< x diff)) expressions that contain idenNfiers. • Second argument to evaluaNon, which takes both an (if test (+ (* x y) diff) 17) expression and an environment. Expr/decl 25 Expr/decl 26 AddiNon: evaluaNon with environment Variable references Syntax: Id Syntax: (+ E1 E2) Id: any iden6fier EvaluaNon rule: Look up and return the value to which Id is bound in the current EvaluaNon rule: environment. • Look-up proceeds by searching from the most-recently added 1. evaluate E1 in the current environment to a value V1 bindings to the least-recently added bindings (front to back in our 2. Evaluate E2 in the current environment to a value V2 representaNon) • If Id is not bound in the current environment, evaluaNng it is “stuck” 3. If V1 and V2 are both numbers then at an unbound variable error. return the arithmeNc sum of V1 + V2. Examples: 4. Otherwise, a type error occurs. • Suppose env is num ⟼ 17, absZero ⟼ -273, true ⟼ #t, num ⟼ 5 • In env, num evaluates to 17 (more recent than 5), absZero evaluates to -273, and true evaluates to #t. Any other name is stuck. Expr/decl 27 Expr/decl 28 define DeclaraNons Environments: Example env0 = ∅ (can write as . in text) Syntax: (define Id E) (define x (+ 1 2)) define: keyword env1 = x ⟼ 3, ∅ (abbreviated x ⟼ 3; can write as x -> 3 in text) Id: any iden6fier (define y (* 4 x)) E: any expression env2 = y ⟼ 12, x ⟼ 3 (most recent binding 2irst) This is a declara)on, not an expression! (define diff (- y x)) We will say a declara)ons are processed, not evaluated env3 = diff ⟼ 9, y ⟼ 12, x ⟼ 3 (define test (< x diff)) Processing rule: env4 = test ⟼ #t, diff ⟼ 9, y ⟼ 12, x ⟼ 3 1.
Recommended publications
  • PS TEXT EDIT Reference Manual Is Designed to Give You a Complete Is About Overview of TEDIT
    Information Management Technology Library PS TEXT EDIT™ Reference Manual Abstract This manual describes PS TEXT EDIT, a multi-screen block mode text editor. It provides a complete overview of the product and instructions for using each command. Part Number 058059 Tandem Computers Incorporated Document History Edition Part Number Product Version OS Version Date First Edition 82550 A00 TEDIT B20 GUARDIAN 90 B20 October 1985 (Preliminary) Second Edition 82550 B00 TEDIT B30 GUARDIAN 90 B30 April 1986 Update 1 82242 TEDIT C00 GUARDIAN 90 C00 November 1987 Third Edition 058059 TEDIT C00 GUARDIAN 90 C00 July 1991 Note The second edition of this manual was reformatted in July 1991; no changes were made to the manual’s content at that time. New editions incorporate any updates issued since the previous edition. Copyright All rights reserved. No part of this document may be reproduced in any form, including photocopying or translation to another language, without the prior written consent of Tandem Computers Incorporated. Copyright 1991 Tandem Computers Incorporated. Contents What This Book Is About xvii Who Should Use This Book xvii How to Use This Book xvii Where to Go for More Information xix What’s New in This Update xx Section 1 Introduction to TEDIT What Is PS TEXT EDIT? 1-1 TEDIT Features 1-1 TEDIT Commands 1-2 Using TEDIT Commands 1-3 Terminals and TEDIT 1-3 Starting TEDIT 1-4 Section 2 TEDIT Topics Overview 2-1 Understanding Syntax 2-2 Note About the Examples in This Book 2-3 BALANCED-EXPRESSION 2-5 CHARACTER 2-9 058059 Tandem Computers
    [Show full text]
  • How to Write Shell Script
    How to write shell script Following steps are required to write shell script: (1) Use any editor like vi or mcedit to write shell script. (2) After writing shell script set execute permission for your script as follows syntax: chmod permission your-script-name Examples: $ chmod +x your-script-name $ chmod 755 your-script-name Note: This will set read write execute(7) permission for owner, for group and other permission is read and execute only(5). (3) Execute your script as syntax: bash your-script-name sh your-script-name ./your-script-name Examples: $ bash bar $ sh bar $ ./bar NOTE In the last syntax ./ means current directory, But only . (dot) means execute given command file in current shell without starting the new copy of shell, The syntax for . (dot) command is as follows Syntax: . command-name Example: $ . foo Now you are ready to write first shell script that will print "Knowledge is Power" on screen. See the common vi command list , if you are new to vi. $ vi first # # My first shell script # clear echo "Knowledge is Power" After saving the above script, you can run the script as follows: $ ./first This will not run script since we have not set execute permission for our script first; to do this type command $ chmod 755 first $ ./first Variables in Shell To process our data/information, data must be kept in computers RAM memory. RAM memory is divided into small locations, and each location had unique number called memory location/address, which is used to hold our data. Programmer can give a unique name to this memory location/address called memory variable or variable (Its a named storage location that may take different values, but only one at a time).
    [Show full text]
  • CS 314 Principles of Programming Languages Lecture 5: Syntax Analysis (Parsing)
    CS 314 Principles of Programming Languages Lecture 5: Syntax Analysis (Parsing) Zheng (Eddy) Zhang Rutgers University January 31, 2018 Class Information • Homework 1 is being graded now. The sample solution will be posted soon. • Homework 2 posted. Due in one week. 2 Review: Context Free Grammars (CFGs) • A formalism to for describing languages • A CFG G = < T, N, P, S >: 1. A set T of terminal symbols (tokens). 2. A set N of nonterminal symbols. 3. A set P production (rewrite) rules. 4. A special start symbol S. • The language L(G) is the set of sentences of terminal symbols in T* that can be derived from the start symbol S: L(G) = {w ∈ T* | S ⇒* w} 3 Review: Context Free Grammar … Rule 1 $1 ⇒ 1& Rule 2 $0 0$ <if-stmt> ::= if <expr> then <stmt> ⇒ <expr> ::= id <= id Rule 3 &1 ⇒ 1$ <stmt> ::= id := num Rule 4 &0 ⇒ 0& … Rule 5 $# ⇒ →A Rule 6 &# ⇒ →B Context free grammar Not a context free grammar CFGs are rewrite systems with restrictions on the form of rewrite (production) rules that can be used. The left hand side of a production rule can only be one non-terminal symbol. 4 A Language May Have Many Grammars Consider G’: The Original Grammar G: 1. < letter > ::= A | B | C | … | Z 1. < letter > ::= A | B | C | … | Z 2. < digit > ::= 0 | 1 | 2 | … | 9 2. < digit > ::= 0 | 1 | 2 | … | 9 3. < ident > ::= < letter > | 3. < identifier > ::= < letter > | 4. < ident > < letterordigit > 4. < identifier > < letter > | 5. < stmt > ::= < ident > := 0 5. < identifier > < digit > 6. < letterordigit > ::= < letter > | < digit > 6. < stmt > ::= < identifier > := 0 <stmt> X2 := 0 <stmt> <ident> 0 := <identifier> := 0 <ident> <letterordigit> <identifier> <digit> <letter> <digit> <letter> 2 X 2 X 5 Review: Grammars and Programming Languages Many grammars may correspond to one programming language.
    [Show full text]
  • Sentential Form
    Some definitions Recall For a grammar G, with start symbol S, any string α such that S ⇒∗ α is called a sentential form α ∗ α • If ∈ Vt , then is called a sentence in L(G) • Otherwise it is just a sentential form (not a sentence in L(G)) A left-sentential form is a sentential form that occurs in the leftmost derivation of some sentence. A right-sentential form is a sentential form that occurs in the rightmost derivation of some sentence. 1 Bottom-up parsing Goal: Given an input string w and a grammar G, construct a parse tree by starting at the leaves and working to the root. The parser repeatedly matches a right-sentential form from the language against the tree’s upper frontier. At each match, it applies a reduction to build on the frontier: • each reduction matches an upper frontier of the partially built tree to the RHS of some production • each reduction adds a node on top of the frontier The final result is a rightmost derivation, in reverse. 2 Example Consider the grammar 1 S → aABe 2 A → Abc 3 | b 4 B → d and the input string abbcde Prod’n. Sentential Form 3 a b bcde 2 a Abc de 4 aA d e 1 aABe – S The trick appears to be scanning the input and finding valid sentential forms. 3 Handles What are we trying to find? A substring α of the tree’s upper frontier that matches some production A → α where reducing α to A is one step in the reverse of a rightmost derivation We call such a string a handle.
    [Show full text]
  • Gnu Coreutils Core GNU Utilities for Version 5.93, 2 November 2005
    gnu Coreutils Core GNU utilities for version 5.93, 2 November 2005 David MacKenzie et al. This manual documents version 5.93 of the gnu core utilities, including the standard pro- grams for text and file manipulation. Copyright c 1994, 1995, 1996, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”. Chapter 1: Introduction 1 1 Introduction This manual is a work in progress: many sections make no attempt to explain basic concepts in a way suitable for novices. Thus, if you are interested, please get involved in improving this manual. The entire gnu community will benefit. The gnu utilities documented here are mostly compatible with the POSIX standard. Please report bugs to [email protected]. Remember to include the version number, machine architecture, input files, and any other information needed to reproduce the bug: your input, what you expected, what you got, and why it is wrong. Diffs are welcome, but please include a description of the problem as well, since this is sometimes difficult to infer. See section “Bugs” in Using and Porting GNU CC. This manual was originally derived from the Unix man pages in the distributions, which were written by David MacKenzie and updated by Jim Meyering.
    [Show full text]
  • EXPR-EU EMS-GEN-00003 Objectives And
    GENERAL EXECUTIVE PROCEDURE EXPR-EU/EMS-GEN-00003 ENVIRONMENTAL v.01 OBJECTIVES AND TARGETS Page 2 of 9 0 CHANGE CONTROL Edition Date Description of the modification 00 Initial edition Process review to ensure greater alignment with the business 01 April 2015 processes. 1 OBJECTIVE AND SCOPE The purpose of this procedure is to define the process to establish the Program of environmental objectives and targets and its follow-up. This procedure shall apply to the facilities and activities included in the EMS scope set out in the file Facilities in the EMS scope . 2 REFERENCES • ISO 14001:2004 standard • EMS Manual • EXPR-EU/EMS-GEN-00001 Identification and assessment of environmental aspects. 3 DEFINITIONS • Environmental objective : an overall environmental goal, arising from the environmental policy and the significant aspects, that an organization sets itself to achieve, and which is quantified where practicable. • Environmental performance : measurable results of an organization’s management of its environmental aspects. • Environmental target : a detailed performance requirement, arising from the environmental objectives, applicable to an organization or parts thereof, and that needs to be set and met in order to achieve those objectives. 4 ABBREVIATIONS • EDPR EU: EDP Renewables Europe. • EMS Manager: EMS Manager in each country. • O&M: Operation and Maintenance department. This document is owned by EDP Renewables. Any printed copies of this document may be outdated. The updated version can be found on the corporate tool “ Internal Documentation” GENERAL EXECUTIVE PROCEDURE EXPR-EU/EMS-GEN-00003 ENVIRONMENTAL v.01 OBJECTIVES AND TARGETS Page 3 of 9 5 PROCEDURE 5.1 ENVIRONMENTAL OBJECTIVES AND TARGETS EDPR EU has permanently in place environmental objectives and targets for the continual improvement of its environmental performance.
    [Show full text]
  • About Jit.Expr
    Advanced Math in Jitter Advanced Math in Jitter Jit.expr Jit.expr is one of the more enigmatic Max objects. Like expr, and vexpr it exists to allow code level manipulation of data. Unlike expr, it works on entire matrices in one go. The key argument to jit.expr is the @expr attribute, which is the math expression to apply to each cell. The expression may be contained in double quote marks. This is not necessary if there are no spaces in the expression, but I find spaces make math easier to read1. Figure 1 shows the archetypical jit.expr test patch. A small matrix is constructed with the same value in each cell. This is fed to specimen jit.expr expressions and the results read from a jit.cellblock. Figure 1. You will notice from figure 1 that jit.expr has a unique syntax. In place of the $i1 and $f1 tokens to denote input data, jit.expr uses the variable expression in[*] where the bracket contains the inlet number. You will also notice that the leftmost inlet is numbered 0. The object does not automatically provide enough inlets for the expression-- if more than two are needed, the @inputs attribute will produce them. There can be at least 64 inlets, although I can't imagine any math expression complex enough to use that many. When jit.expr receives a matrix, it applies the expression to each cell in the input matrix and outputs a matrix of the same size. If you want to define a constant size for the output 1 If you use quotes, but don't have any spaces, the quotes will vanish when the object is completed.
    [Show full text]
  • GPL-3-Free Replacements of Coreutils 1 Contents
    GPL-3-free replacements of coreutils 1 Contents 2 Coreutils GPLv2 2 3 Alternatives 3 4 uutils-coreutils ............................... 3 5 BSDutils ................................... 4 6 Busybox ................................... 5 7 Nbase .................................... 5 8 FreeBSD ................................... 6 9 Sbase and Ubase .............................. 6 10 Heirloom .................................. 7 11 Replacement: uutils-coreutils 7 12 Testing 9 13 Initial test and results 9 14 Migration 10 15 Due to the nature of Apertis and its target markets there are licensing terms that 1 16 are problematic and that forces the project to look for alternatives packages. 17 The coreutils package is good example of this situation as its license changed 18 to GPLv3 and as result Apertis cannot provide it in the target repositories and 19 images. The current solution of shipping an old version which precedes the 20 license change is not tenable in the long term, as there are no upgrades with 21 bugfixes or new features for such important package. 22 This situation leads to the search for a drop-in replacement of coreutils, which 23 need to provide compatibility with the standard GNU coreutils packages. The 24 reason behind is that many other packages rely on the tools it provides, and 25 failing to do that would lead to hard to debug failures and many custom patches 26 spread all over the archive. In this regard the strict requirement is to support 27 the features needed to boot a target image with ideally no changes in other 28 components. The features currently available in our coreutils-gplv2 fork are a 29 good approximation. 30 Besides these specific requirements, the are general ones common to any Open 31 Source Project, such as maturity and reliability.
    [Show full text]
  • GNU Coreutils Core GNU Utilities for Version 9.0, 20 September 2021
    GNU Coreutils Core GNU utilities for version 9.0, 20 September 2021 David MacKenzie et al. This manual documents version 9.0 of the GNU core utilities, including the standard pro- grams for text and file manipulation. Copyright c 1994{2021 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". i Short Contents 1 Introduction :::::::::::::::::::::::::::::::::::::::::: 1 2 Common options :::::::::::::::::::::::::::::::::::::: 2 3 Output of entire files :::::::::::::::::::::::::::::::::: 12 4 Formatting file contents ::::::::::::::::::::::::::::::: 22 5 Output of parts of files :::::::::::::::::::::::::::::::: 29 6 Summarizing files :::::::::::::::::::::::::::::::::::: 41 7 Operating on sorted files ::::::::::::::::::::::::::::::: 47 8 Operating on fields ::::::::::::::::::::::::::::::::::: 70 9 Operating on characters ::::::::::::::::::::::::::::::: 80 10 Directory listing:::::::::::::::::::::::::::::::::::::: 87 11 Basic operations::::::::::::::::::::::::::::::::::::: 102 12 Special file types :::::::::::::::::::::::::::::::::::: 125 13 Changing file attributes::::::::::::::::::::::::::::::: 135 14 File space usage ::::::::::::::::::::::::::::::::::::: 143 15 Printing text :::::::::::::::::::::::::::::::::::::::
    [Show full text]
  • Expr Family Objects by Shahrokh Yadegari
    Expr family objects by Shahrokh Yadegari To see a directory listing of downloadable files, which also inlcudes older releases, click here . Back to the Software Page Expr, Expr~, Fexpr~ Based on original sources from IRCAM's jMax Released under BSD License. The expr family is a set of C-like expression evaluation objects for the graphical music language Pd and it is now part of the vanilla distribution. New Additions in version 0.4 Expr, expr~, and fexpr~ now support multiple expressions separated by semicolons which results in multiple outlets. Variables are supported now in the same way they are supported in C. Variables have to be defined with the "value" object prior to execution. A new if function if (condition-expression, IfTure-expression, IfFalse-expression) has been added. New math functions added. New shorthand notations for fexpr~ have been added. $x ->$x1[0] $x# -> $x#[0] $y = $y1[-1] and $y# = $y#[-1] New 'set' and 'clear' methods were added for fexpr~ clear - clears all the past input and output buffers clear x# - clears all the past values of the #th input clear y# - clears all the past values of the #th output set x# val-1 val-2 ... - sets as many supplied value of the #th input; e.g., "set x2 3.4 0.4" - sets x2[-1]=3.4 and x2[-2]=0.4 set y# val-1 val-2 ... - sets as many supplied values of the #th output; e.g, "set y3 1.1 3.3 4.5" - sets y3[-1]=1.1 y3[-2]=3.3 and y3[-3]=4.5; set val val ..
    [Show full text]
  • From: Mr. Sohit Agarwal Lecturer, Dept. of CS/IT, JNIT 22 CONTENTS II
    From: Mr. Sohit Agarwal Lecturer, Dept. of CS/IT, JNIT 22 CONTENTS II ((ii) IInnttrroodduuccttiioonoof UUNN IIXX 44 ((iiii)) TTyyppees oof SShheelll 55 Commands 1.1. ddaattee 88 22.. wwhhoo 10 33.. ccaall 12 44.. llss 14 55.. eedd 16 66.. ccaatt 18 7.7. touch 20 88.. wwcc 22 99.. mmoorree 24 1100.. eecchhoo 26 1111.. pprr 28 1122.. bbcc 30 1133.. mmkkddiirr 32 1144.. rrmmddiirr 34 1155.. hheeaadd 36 16. tail 38 1177.. ppss 40 1188.. kkiillll 42 33 1199.. ccpp 44 2200.. vvii 46 2211.. ppwwdd 48 2222.. sshh 50 2233.. ggrreepp 52 2244.. ccmmpp 54 25. diff 56 4 CONTENTS Programs 1. Program to print Hello World 58 2. Program to obtain all files in current directory 58 3. Program to accept a number from user and print the same 60 4. Program to check who all are logged on 60 5. Program for addition of two numbers 62 6. Program for multiplication of two numbers 62 7. Program for adding the digits of a number 64 8. Program for reversing a number 64 9. Program to calculate Simple Interest 66 10. Program to check if given number is even or odd 66 11. Program to demonstrate syntax of while 68 12. Program to demonstrate syntax of switch 68 13. Program to calculate area and circumference of a circle 70 14. Program to check if the year is a leap year or not 70 15. Program to find the factorial of a number 72 16. Program to print the Fibonacci sequence 72 17. Program to find the shortest of three numbers 74 18.
    [Show full text]
  • Stacks and Trees Subclasses and Inheritance
    Stacks and Trees Subclasses and Inheritance Op5onal assignment 10 stacks, pos<ix, recursive traversal • CIS 210 Idutorob: The Incredible Duck Tournament of Robots (Actually Sudoku, but Sudoku is kind of like duck-sled racing. ) REMINDER: TOURNAMENT ENTRIES DUE TODAY AT 5 Photo credits: hAp://www.city-data.com/forum/alaska/1522185- robot-ken-robodog-go-dog-sledding.html, hp://steamcommunity.com/groups/rdzgroup • CIS 210 Op5onal assignment Simple pos<ix calculator ... with a twist $ python3 symcalc.py - 3 5 + 7 * 4 5 * Stack: ((3+5)*7); (4*5); # Stack: ((3+5)*7); 20; + Stack: (((3+5)*7)+20); # Stack: 76; quit Thank you for your paence. Sorry for any bugs. • CIS 210 Pos<ix Our customary notaon is infix: (3 + 5) * 7 (operators + and * between operands) Pos(ix places operators aer operands: 3 5 + 7 * Prefix places operators before operands * + 3 5 7 Pos<ix and prefix don’t require parentheses or operator precedence. Evaluate pos<ix on a stack. • CIS 210 Stack A stack is a sequence that supports inser5on and dele5on at one end push(x) adds to top pop( ) takes element from top [ ] Python lists can be stacks: stack.append(x) is push(x) stack.pop() is pop() • CIS 210 Stack A stack is a sequence that supports inser5on and dele5on at one end 5.3 s = [ ] s.append(5.3) • CIS 210 Stack A stack is a sequence that supports inser5on and dele5on at one end top 3.7 5.3 s = [ ] s.append(5.3) s.append(3.7) • CIS 210 Stack A stack is a sequence that supports inser5on and dele5on at one end top 4.0 3.7 5.3 s = [ ] s.append(5.3) s.append(3.7) s.append(4.0) • CIS
    [Show full text]