LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.

Slides:



Advertisements
Similar presentations
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
Advertisements

COMP234 Perl Printing Special Quotes File Handling.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Administrivia Homework 1 graded – you should have gotten an from me.
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
Introduction to Python
1ex.1 Perl Programming for Biology Exercise 1 The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman.
Perl File I/O and Arrays. File I/O Perl allows to open a file to read, write, or append As well as pipe input or output to another program. —We get to.
Guide To UNIX Using Linux Third Edition
2ex.1 Lists and Arrays. 2ex.2 Comments on exercises Always run your script with “ perl -w ” and take care of all warnings  submitted scripts should not.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 1 (submit by midnight Saturday) Some slides.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Introduction to Computational Linguistics Programming I.
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Continuing with Perl Homework 3: first Perl homework – due Sunday by midnight – one PDF file, by .
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 2 (submit by midnight Friday) Today is Perl.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong. Administrivia Homework 2 graded.
IDL Tutorial Day 1 Goals: 1) Introduce IDL basics 2) Describe fundamental IDL structures Angela Des Jardins
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Python Let’s get started!.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
2.1 Lesson 2: Scalar Functions and Arrays “Perl programming is an empirical science!” - Larry Wall.
Organization of Programming Languages Meeting 37 April 18, 2016.
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong.
Last week: We talked about: History of C Compiler for C programming
C++ First Steps.
Topics Designing a Program Input, Processing, and Output
Input from STDIN STDIN, standard input, comes from the keyboard.
Python Let’s get started!.
Pamela Moore & Zenia Bahorski
Shell Scripting March 1st, 2004 Class Meeting 7.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
Introduction to C Topics Compilation Using the gcc Compiler
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
C Basics.
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong.
CSCI206 - Computer Organization & Programming
LING 408/508: Computational Techniques for Linguists
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Arrays, For loop While loop Do while loop
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
Perl Variables: Array Web Programming.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
Topics Designing a Program Input, Processing, and Output
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
CSE 303 Concepts and Tools for Software Development
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Lab 4: Introduction to Scripting
Introduction to Programming
Text Copyright (c) 2017 by Dr. E. Horvath
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 7 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
Introduction to Python
Presentation transcript:

LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong

Administrivia Today's Topics Quick Homework 4 graded (you should have an email from me) Today's Topics Terminal log from last time A note on Windows 10 and quoting Review of Homework 4 Continuing on with perlintro (scalars and arrays)

Terminal: from last time ~$ perl test.perl Can't open perl script "test.perl": No such file or directory ~$ pwd /Users/sandiway ~$ cd Desktop Desktop$ pwd /Users/sandiway/Desktop Desktop$ perl test.perl Hello, worldDesktop$ perl test.perl Hello, world Hello, world\nDesktop$ perl test.perl Desktop$ perl test.perl Hello, world Desktop$ perl -e 'print "Hello, World"' Hello, WorldDesktop$ perl -e 'print "Hello, World\n"' Hello, World Desktop$ perl -le 'print "Hello, World"' Name "main::Hello" used only once: possible typo at test.perl line 3. print() on unopened filehandle Hello at test.perl line 3.

Terminal: from last time Desktop$ perl test.perl Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 3. Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 4. Execution of test.perl aborted due to compilation errors. This is a stringDesktop$ perl test.perl This is a string\nDesktop$ perl test.perl This is a string Desktop$ perl test.perl Name "main::Hello" used only once: possible typo at test.perl line 3. Name "main::Helo" used only once: possible typo at test.perl line 4. Use of uninitialized value $Helo in string at test.perl line 4.

Terminal: from last time Desktop$ perl test.perl Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 3. Global symbol "$Helo" requires explicit package name (did you forget to declare "my $Helo"?) at test.perl line 4. Execution of test.perl aborted due to compilation errors. Desktop$ MacOS: aquamacs editor TextEdit Linux: nano emacs Windows 10: Notepad

Terminal: from last time Windows 10 command prompt single quotes not recognized as quotes double quotes can be used inside the (initial) double quotes, everything will be passed to Perl: you can use single quotes you can escape double quotes, i.e. \" to get a double quote.

Terminal: from last time You can also use PowerShell in Windows 10: both single and double quotes can be used as quoting characters in the shell. Inside the initial quotes, you can escape any quotes that need to be passed to Perl.

Terminal: from last time ~$ cd Desktop Desktop$ python3 Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello, World") Hello, World >>> print "Hello, world\n"; File "<stdin>", line 1 print "Hello, world\n"; >>> SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, world\n")? >>> print "Hello, world\n"; File "<stdin>", line 1 print "Hello, world\n"; ^ >>> >>> print("Hello, World") Hello, World >>> print('Hello, World') >>> print('Hello, World\n') >>> print('Hello, World\n\n\n\n\n')

Homework 4 Review 1. Commas are important people. Q2: Run the these two sentences on the Berkeley Parser. Critique the parse. (http://tomato.banatao.berkeley.edu:8080/parser/parser.html) Q3: Compare with the Google Parser. Critique the dependency parses. (https://cloud.google.com/natural-language/)

Homework 4 Review Berkeley Parser

Homework 4 Review Google Parser ATTR - link between a verb like 'be/seem/appear' and its complement https://nlp.stanford.edu/software/dependencies_manual.pdf attr has been removed as a relation. attr was a relation intended for the complement of a copular verb such as “to be”, “to seem”, “to appear”. Mainly, it was used for WHNP complements. (The relation attr was meant to stand for “attributive” but that was arguably a misuse of the word.)

Homework 4 Review Periods are important, people! Compare!

Homework 4 Review Capitalization is important, people! Compare!

print as a statement vs. function Perl Python3 Same behavior, different assumptions about end of line (\n) from these two programming languages "\" is the escape character Note also the differences in syntax: (..) in Python3, no parentheses (needed) in Perl ; need to separate the statements in Perl, none in Python

Perl vs. Python3 Scalars: (basically things that take up one 32/64 bit word of memory) variables begin with ($) - no such type requirement in Python Numbers (integer, floating point) Python includes complex numbers (cmath library) Strings (double ".." or single quoted '..') References (pointers to (non-)scalars)

Perl vs. Python3 Variable interpolation Perl: Python3: Python2.7: print "My name is $name\n"; print "My name is \$name\n"; print 'My name is \$name\n'; Python3: print("My name is", name) Python2.7: Note: white spacing

perlintro: Arrays like a simple ordered list… (in Python, we use a list) Literal: @ARRAY = ( … , … , …) (round brackets; comma separator) Python: array = [… , … , … ] Access: $ARRAY[ INDEX] (zero-indexed; negative indices ok; slices ok) Python: array[index] Index of last element:  $#array (a scalar) Python: len(array)-1 array[-1] Coercion @ARRAY = number of elements in scalar context Python: len(array) Built-in functions: sort @ARRAY; reverse @ARRAY,; push @ARRAY, $ELEMENT; pop @ARRAY; shift @ARRAY; unshift @ARRAY, $ELEMENT, splice @ARRAY, $OFFSET, $LENGTH, $ELEMENT $ELEMENT above can be @ARRAY Python: array.sort(), array.reverse() Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)

perlintro Notes from the tutorial: semicolon (;) is not always necessary Command separator semantics vs. end of command (termination) token Best practice? Terminate every command with a semicolon Variable types: Every variable type has its own namespace. This means that $foo and @foo are two different variables. It also means that $foo[1] is a part of @foo, not a part of $foo. This may seem a bit weird, but that's okay, because it is weird.

Perl Arrays Arrays: A note on output: Idea: list of scalars like a simple ordered list (cf. Python lists) access by index: 0,1,2,… negative indices count from the end -2..-1 A note on output: print @a zeroonetwothreefour print "@a" zero one two three four controlled by system variable $" default value: a space

perlintro: Perl Arrays like a simple ordered list… (in Python, we use a list) Literal: @ARRAY = ( … , … , …) (round brackets; comma separator) Python: array = [… , … , … ] Access: $ARRAY[ INDEX] (zero-indexed; negative indices ok; slices ok) Python: array[index] Index of last element:  $#array (a scalar) Python: len(array)-1 (access: array[-1])

Shell quoting Bash shell (MacOS, Linux): cf. Windows 10 slide earlier manual: http://www.gnu.org/software/bash/manual/ can't write: perl -e '@a=(\'a\',\'b\',\'c\'); print "@a\n"'

Shell quoting Bash shell (MacOS, Linux): can write: perl -e "@a=(\"a\",\"b\",\"c\"); print \"@a\n\""

perlintro: Perl Arrays like a simple ordered list… (in Python, we use a list) Coercion @ARRAY = number of elements in scalar context Python (no coercion): len(array) Built-in functions: sort @ARRAY; reverse @ARRAY,; push @ARRAY, $ELEMENT; pop @ARRAY; shift @ARRAY; unshift @ARRAY, $ELEMENT, splice @ARRAY, $OFFSET, $LENGTH, $ELEMENT $ELEMENT above can be @ARRAY Python: array.sort(), array.reverse(), NO push (use array.append() instead), array.pop(), No shift/unshift etc… Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)

perlintro: Perl Arrays Similar to pop/push, but operates at the left end of the array Python doesn't have these defined but can be simulated via slicing and concatenation: array[1:] list + array

perlintro: Perl Arrays