/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental data structures /06/14(Tue) / Memory Management

Similar documents
/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

I117 II I117 PROGRAMMING PRACTICE II DEBUG Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II SOFTWARE DEVELOPMENT ENV. 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II HASH Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

I117 II I117 PROGRAMMING PRACTICE II 2 SOFTWARE DEVELOPMENT ENV. 2 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu

Python Speed Learning

I117 II I117 PROGRAMMING PRACTICE II SCRIPT LANGUAGE 1 Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara

listings-ext

haskell.gby

Python Speed Learning

PowerPoint Presentation

永和システムマネジメント SP 安井力 東京支社 Python 勉強会実習資料 2005/12/28 この資料の使い方最初から順に試してください 初心者は 書かれたとおり入力して ほかにも似た例を試してみてください 初級者は 書かれたとおり入力して なぜそれで動くのか調べてください 中級者は 設問か

Boo Boo 2 Boo 2.NET Framework SDK 2 Subversion 2 2 Java 4 NAnt 5 Boo 5 5 Boo if 11 for 11 range 12 break continue 13 pass

num2.dvi


1.indd

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

Ruby演習テキスト1


たのしいプログラミング Pythonではじめよう!

r07.dvi

ohp07.dvi

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

2

syspro-0405.ppt

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

6-1

I117 プログラミング演習II

,,,,., C Java,,.,,.,., ,,.,, i


Dec , IS p. 1/60

3 3.1 algebraic datatype data k = 1 1,1... 1,n1 2 2,1... 2,n2... m m,1... m,nm 1 m m m,1,..., m,nm m 1, 2,..., k 1 data Foo x y = Alice x [y] B

RubyKaigi2009 COBOL

Ruby Ruby ruby Ruby G: Ruby>ruby Ks sample1.rb G: Ruby> irb (interactive Ruby) G: Ruby>irb -Ks irb(main):001:0> print( ) 44=>


2

r1.dvi

tuat1.dvi

Java updated

BASIC / / BA- SIC Web 1/10 1/10 / / JavaScript

1 VisBAR edu H 2 O.....

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

untitled

(CC Attribution) Lisp 2.1 (Gauche )

つくって学ぶプログラミング言語 RubyによるScheme処理系の実装

(pack ) Toplevel

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

(Basic Theory of Information Processing) Fortran Fortan Fortan Fortan 1

PowerPoint プレゼンテーション

Parametric Polymorphism

piyo0705B.rtfd

LiveCode初心者開発入門サンプル

導入基礎演習.ppt

untitled

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b


untitled


Kyosuke MOROHASHI


listings-ext

Copyright c 2008 Zhenjiang Hu, All Right Reserved.

JEB Plugin 開発チュートリアル 第4回

(Java/FX ) Java CD Java version Java VC++ Python Ruby Java Java Eclipse Java Java 3 Java for Everyone 2 10 Java Midi Java JavaFX Shape Canvas C

RL_tutorial

K227 Java 2

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp

随筆 私本太平記

I 2 tutimura/ I 2 p.1/??

ohp1.dvi

untitled

presen.gby

joho07-1.ppt

C言語によるアルゴリズムとデータ構造

28 Docker Design and Implementation of Program Evaluation System Using Docker Virtualized Environment

RHEA key

Emacs Ruby..

:56 1 (Forward kinematics) (Global frame) G r = (X, Y, Z) (Local frame) L r = (x, y, z) 1 X Y, Z X Y, Z 1 ( ) ( ) 1.2 (Joint rotati

test.gby

5-2 print(i, "\n") print("-- while--\n") while i < 2 j = print(i, ",", j, "\n") print("-- while--\n") while j < 3 print(i, ",", j, "\n") j = j + 1 pri

I I / 68

Java演習(4) -- 変数と型 --


Ruby 50 Ruby UTF print, \n [Ruby-1] print("hello, Ruby.\n") [Ruby-2] Hello, Ruby. [Ruby-3] print("hello, \"Ruby\".\n") 2 [Ruby-4] seisuu = 10 pr

明解Java入門編

Python C/C++ IPMU IRAF

2

2011 Future University Hakodate 2011 System Information Science Practice Group Report Project Name Visualization of Code-Breaking Group Name Implemati

r08.dvi


pptx

johokiso-char.pdf.pdf

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

jssst-ocaml.mgp

ohp08.dvi

Microsoft PowerPoint - 11RubyIntro-No02.ppt [互換モード]

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

新・明解Java入門

untitled

Transcription:

I117 II I117 PROGRAMMING PRACTICE II OTHER LANGUAGES Research Center for Advanced Computing Infrastructure (RCACI) / Yasuhiro Ohara yasu@jaist.ac.jp

/ SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming 2. 2011/06/09(Thu) / Fundamental data structures 3. 2011/06/14(Tue) / Memory Management 1 4. 2011/06/16(Thu) / Memory Management 2 5. 2011/06/21(Tue) / Debugging 6. 2011/06/23(Thu) / Software Development Env. 1 7. 2011/06/28(Tue) / Software Development Env. 2 8. 2011/06/30(Thu) / Data Structure : Tree 9. 2011/07/05(Tue) / Data Structure: Hash 10. 2011/07/07(Thu) / Understanding Programs 1 11. 2011/07/12(Tue) / Understanding Programs 2 12. 2011/07/14(Thu) / Script Language 1 13. 2011/07/19(Tue) / Script Language 2 14. 2011/07/21(Thu) / Other Languages 15. 2011/07/26(Tue) / Examination

/ FINAL REPORT free topic : The deadline: 7/26(Tue) Submit the source code, and the report. by e-mail: i117report@jaist.ac.jp by 7/26(Tue) 23:59. / Sound file converter / web crawler (CalDAV) calendar program new shell, editor, window manager rsync encrypt/decrypt, rsync markov-chain program The final report must have deep consideration

/ TODAY'S INDEX python

PYTHON

PYTHON C sh Java Ruby Python C++ Perl Erlang LISP Scheme ML OCaml Haskel

PYTHON (very-high-level language) BBC Monty Python s Flying Circus C

PYTHON Python 2.x 2.7 2.xPython Python 3.x Python 2.x Python 3.x

PYTHON CPython C PythonCPython JPython Java Java VM PyPy PythonPython IronPython C#.NET Unladen Swallow CPython LLVMJIT Stackless Python Python Eve OnlineSecond LifeMMORPGCisco IronPort

HELLO WORLD! print python $ python >>> print Hello World Hello World! Ctrl+D $ cat hello.py print Hello World $ python hello.py Hello World! Python.py

HELLO WORLD! IN PYTHON 3.X Python 3.x print() >>> print( Hello World ) Hello World!

PYTHON Shell1 #! $ cat hello.py #!/usr/bin/env python print Hello World $ chmod +x hello.py $./hello.py Hello World!

Python ASCII # -*- coding: encoding -*- UTF-8 $ cat morning.py #!/usr/bin/env python # -*- coding: utf-8 -*- print u $./morning.py

PYTHON Unicode

Hello World! Hello World! \ \ \ \n \t\\\ >>> print Hello \ World!\ Hello World! >>> print Hello\\World! Hello\World! >>> print Hello\nWorld! Hello World

+ >>> Hello + World! HelloWorld! * >>> Hello * 5 'HelloHelloHelloHelloHello' len() >>> len( Hello ) 5

[] 0 : -1-2 >>> word = Hello >>> word[1] # 1 e >>> word[1:4] # 13 ell >>> word[:3] # 02 hel # >>> word[1:] # 1 ello # >>> word[:-2] # 3 hel

UNICODE Python 2.x str unicode u hello u unicode type >>> type('hello') <type 'str'> >>> type(u'') <type 'unicode'> str unicode >>> [0] # 1 '\xe3' >>> u [0] # 1 u'\u3053 >>> len('') 15 # 15 >>> len(u'') 5 # 5

UNICODE IN PYTHON 3.X Python 3.x Unicode str (2.x) bytes (3.x) hello b hello Python 2.6 b hello Unicode unicode (2.x) str (3.x) u hello hello

UNICODESTR unicodeencode() >>> u.encode( utf-8 ) # UTF-8 '\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab \xe3\x81\xa1\xe3\x81\xaf >>> u.encode( sjis ) # Shift-JIS '\x82\xb1\x82\xf1\x82\xc9\x82\xbf\x82\xcd' unicodeunicode() >>> unicode('\x82\xb1\x82\xf1\x82\xc9\x82\xbf \x82\xcd', 'sjis') u'\u3053\u3093\u306b\u3061\u306f' >>> print unicode('\x82\xb1\x82\xf1\x82\xc9\x82\xbf \x82\xcd', 'sjis')

PYTHON list deque set tuple dict

LIST C [] >>> foo = ['apple', 'orange', 100, 200] >>> foo ['apple', 'orange', 100, 200] [] >>> foo[2] 100 [:] >>> foo[1:3] ['orange', 100] >>> foo[:2] ['apple', 'orange']

LIST + >>> foo = ['apple', 'orange', 100, 200] >>> foo + ['banana', 500] ['apple', 'orange', 100, 200, 'banana', 500] >>> foo ['apple', 'orange', 100, 200, 'banana', 500] >>> foo[1] = 'cherry' >>> foo ['apple', 'cherry', 100, 200, 'banana', 500] >>> foo[2:3] = [300, 400] >>> foo ['apple', 'cherry', 300, 400, 200, 'banana', 500]

LIST >>> a = [66.25, 333, 333, 1, 1234.5] >>> print a.count(333), a.count(66.25) # 2 1 >>> a.insert(2, -1) # 2-1 >>> a [66.25, 333, -1, 333, 1, 1234.5] >>> a.index(333) # 333 1 >>> a.remove(333) # 333 >>> a [66.25, -1, 333, 1, 1234.5] >>> a.reverse() # >>> a [1234.5, 1, 333, -1, 66.25] >>> a.sort() # >>> a [-1, 1, 66.25, 333, 1234.5] >>> len(a) # 5

LIST appendpop >>> stack = [3, 4, 5] >>> stack.append(6) # 6 >>> stack.append(7) # 7 >>> stack [3, 4, 5, 6, 7] >>> stack.pop() # 7 >>> stack [3, 4, 5, 6] >>> stack.pop() 6 >>> stack.pop() 5 >>> stack [3, 4]

DEQUE deque >>> import collections # collections >>> queue = collections.deque([1, 2, 3]) # >>> queue deque([1, 2, 3]) >>> queue.append(4) # 4 >>> queue.append(5) # 5 >>> queue deque([1, 2, 3, 4, 5]) >>> queue.popleft() # >>> queue.popleft() >>> queue deque([3, 4, 5])

SET >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana ] >>> fruit = set(basket) # set >>> fruit set(['orange', 'pear', 'apple', 'banana']) >>> orange in fruit # orange True # >>> 'crabgrass' in fruit False >>> fruit.add( peach ) # peach >>> fruit set(['apple', 'banana', 'orange', 'peach', 'pear']) >>> fruit.remove( orange ) # orange set(['apple', 'banana', 'peach', 'pear'])

TUPLE list tuple tuplec >>> point = 10, 30 # tuple >>> point (10, 30) >>> point[0] # 0 10 >>> x, y = point # x, y tuple >>> x 10 >>> y 30

DICT KeyValue Key >>> fruit = { orange : 100, apple : 200} # >>> fruit[ orange ] # key orange 100 >>> fruit[ orange ] = 300 # orange >>> fruit {'orange': 300, 'apple': 200} >>> fruit[ banana ] = 500 # banana >>> fruit {'orange': 300, 'apple': 200, 'banana': 500} >>> del fruit[ apple ] # apple >>> fruit {'orange': 300, 'banana': 500}

PYTHON if for range() continuebreak pass

Python 4 CPython C if (a == b) { a = b * 2; printf( %d\n, a); } Python if a == b: a = b * 2 print a CK&RGNUBSD

IF Cif >>> x = 3 >>> if x < 0:... print x is less than zero... elif x == 0:... print zero... elif x == 1:... print single... else... print more... more

FOR forcfor >>> animal = [ dog, cat, bird ] >>> for a in animal: # animala... print a... dog cat bird

FORDICT dictkeys()key >>> fruit = {'orange': 100, 'apple': 200, 'banana': 400} >>> for f in fruit.keys():... print f, :, fruit[f]... orange : 100 apple : 200 banana : 400 iteritems()3.xitems() >>> fruit = {'orange': 100, 'apple': 200, 'banana': 400} >>> for k, v in fruit.iteritems():... print k, :, v... orange : 100 apple : 200 banana : 400

RANGE() range() >>> range(10) # 09 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(3, 10) # 39 [3, 4, 5, 6, 7, 8, 9] >>> range(3, 20, 4) # 320 [3, 7, 11, 15, 19] # 4

CFOR range() >>> month = [ April, May, June, July ] >>> for i in range(len(month)):... print i, month[i]... 0 April 1 May 2 June 3 July xrange() xrange()

CONTINUEBREAK break continue >>> for n in range(2, 10):... for x in range(2, n):... if n % x == 0:... print n, 'equals', x, '*', n/x... break... else: # Cforelse... # else... print n, 'is a prime number'... 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3

PASS pass >>> while is_func(): # is_func()... pass #

PYTHON def lambda C++ f : X Y Z 2f(x, y)gf f(x, y) = g(x)(y) g : X (Y Z)

def return >>> def twice(x): # def,... return x * 2 # return... >>> twice(100) # 200 >>> twice(45) 90 >>> x # xtwice Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name x is not defined

C >>> def n_times(x, n = 2): # n... return x * n... >>> n_times(40) # n n = 2 80 >>> n_times(40, 3) # n 120

>>> def person(name, age):... print 'name = ' + name... print 'age = ' + str(age)... >>> person( Alice, 16) # name = Alice age = 16 >>> person(age = 18, name = Bob ) # name = Bob age = 18

** * >>> def var_args(*args, **kargs):... print args... print kargs... >>> var_args(1, 2, 3, 'foo', 'bar', name = 'Alice', age = 20) (1, 2, 3, foo, bar ) # { age : 20, name : Alice } #

* ** >>> range(2, 7) # [2, 3, 4, 5, 6] >>> args = [2, 7] >>> range(*args) # [2, 3, 4, 5, 6] >>> def n_times(x, n):... return x * n... >>> args = {'n': 100, 'x': 3} >>> n_times(**args) # 300

LAMBDA lambda n_times() >>> f = lambda x, n: x * n >>> f(10, 4) 40 lambda defreturn

n >>> def n_times_f(n): # n... return lambda x: n_times(x, n) # n... >>> f1 = n_times_f(2) # 2 >>> f1(10) 20 >>> f1(15) 30 >>> f2 = n_times_f(5) # 5 >>> f2(10) 50 >>> f2(15) 75

2x, ysort() x < y, x == y, x > y -1, 0, 1 >>> people = [('Bob', 20), ('Carol', 15), ('Alice', 17)] >>> people [('Bob', 20), ('Carol', 15), ('Alice', 17)] >>> people.sort() # >>> people # [('Alice', 17), ('Bob', 20), ('Carol', 15)] >>> people.sort(lambda x, y: x[1] - y[1]) # >>> people # [('Carol', 15), ('Alice', 17), ('Bob', 20)]

PYTHON filter map reduce

FILTER filter(func, list) func list 23 >>> def f(x):... return x % 2!= 0 and x % 3!= 0... >>> filter(f, range(2, 25)) [5, 7, 11, 13, 17, 19, 23]

MAP map(func, list) func list 3 >>> def cube(x):... return x**3 # **... >>> map(cube, range(1, 11)) [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]

REDUCE 2 reduce(func, list, init) func list init >>> reduce(lambda x, y: x + y,... [[1, 2, 3], [4, 5], [6, 7, 8]],... []) [1, 2, 3, 4, 5, 6, 7, 8] step 1: [1, 2, 3] + [4, 5] [6, 7, 8] + [] step 2: [1, 2, 3, 4, 5] + [6, 7, 8] result: [1, 2, 3, 4, 5, 6, 7, 8]

{ x * x x L} >>> [x * x for x in range(10)] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] { x * x x * x > 20, x L} >>> [x * x for x in range(10) if x * x > 20] [25, 36, 49, 64, 81]

PYTHON dir()

Python11 my_echo.pyecho() $ cat my_echo.py def echo(word): print word my_echoecho $ python >>> import my_echo # >>> my_echo.echo( Hello World! ) # Hello World!

/ SCHEDULE 1. 2011/06/07(Tue) / Basic of Programming 2. 2011/06/09(Thu) / Fundamental data structures 3. 2011/06/14(Tue) / Memory Management 1 4. 2011/06/16(Thu) / Memory Management 2 5. 2011/06/21(Tue) / Debugging 6. 2011/06/23(Thu) / Software Development Env. 1 7. 2011/06/28(Tue) / Software Development Env. 2 8. 2011/06/30(Thu) / Data Structure : Tree 9. 2011/07/05(Tue) / Data Structure: Hash 10. 2011/07/07(Thu) / Understanding Programs 1 11. 2011/07/12(Tue) / Understanding Programs 2 12. 2011/07/14(Thu) / Script Language 1 13. 2011/07/19(Tue) / Script Language 2 14. 2011/07/21(Thu) / Other Languages 15. 2011/07/26(Tue) / Examination

/ FINAL REPORT free topic : The deadline: 7/26(Tue) Submit the source code, and the report. by e-mail: i117report@jaist.ac.jp by 7/26(Tue) 23:59. / Sound file converter / web crawler (CalDAV) calendar program new shell, editor, window manager rsync encrypt/decrypt, rsync markov-chain program The final report must have deep consideration