Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Kent OHASHI
    @lagenorhynque
    Pythonでの例
    >>> def plus(*args): return sum(args)
    ...
    >>> plus(1,2,3)
    6
    >>> plus(*[1,2,3])
    6
    Kent OHASHI
    @lagenorhynque
    concat :: Foldable t => t [a] -> [a]
    [Prelude]
    > concat [[1,2,3], [4,5]]
    [1,2,3,4,5]
    Kent OHASHI
    @lagenorhynque
    Kent OHASHI
    @lagenorhynque
    user> (read-string "'(1 2 3)")
    (quote (1 2 3))
    Satoshi Imai
    @masatoi
    (defun f (x)
    (declare (type fixnum x))
    (+ x 1))
    CL-USER> (defun f (x)
    (declare (optimize (speed 3) (safety 0) (debug 0))
    (type fixnum x))
    (+ x 1))
    WARNING: redefining COMMON-LISP-USER::F in DEFUN
    F
    CL-USER> (disassemble #'f)
    ; disassembly for F
    ; Size: 29 bytes. Origin: #x100B83363C
    ; 3C: 48FFC1 INC RCX ; no-arg-parsing entry point
    ; 3F: 488BD1 MOV RDX, RCX
    ; 42: 48D1E2 SHL RDX, 1
    ; 45: 710C JNO L0
    ; 47: 488BD1 MOV RDX, RCX
    ; 4A: 41BBE008B021 MOV R11D, #x21B008E0 ; ALLOC-SIGNED-BIGNUM-IN-RDX
    ; 50: 41FFD3 CALL R11
    ; 53: L0: 488BE5 MOV RSP, RBP
    ; 56: F8 CLC
    ; 57: 5D POP RBP
    ; 58: C3 RET
    Kent OHASHI
    @lagenorhynque
    rainbow-lisp.png
    Kent OHASHI
    @lagenorhynque
    (def suffixes
      '(JD MD DO PharmD Sr. Jr.))
    
    (defn last-name'
      "Select the last name from a name represented as a list."
      [name]
      (if (some #(= % (last name)) suffixes)
        (last-name' (butlast name))
        (last name)))
    Satoshi Imai
    @masatoi
    (defparameter *title* '(MD Jr.))
    
    (defun last1 (lst)
      (car (last lst)))
    
    (defun last-name (name)
      (if (member (last1 name) *title*)
          (last1 (butlast name 1))
          (last1 name)))
    
    (last-name '(Rex Morgan MD))
    Kent OHASHI
    @lagenorhynque
    paip.chapter01.core> (last-name' '(Rex Morgan MD))
    Morgan
    (defn last-name'
      "Select the last name from a name represented as a list."
      [name]
      (let [lname (last name)]
        (if (some #(= % lname) suffixes)
          (last-name' (butlast name))
          lname)))
    Satoshi Imai
    @masatoi
    (defun power (x n)
      (expt x n))
    (defun square (x)
      (* x x))
    
    (defun power (x n)
      (cond  ((= n 0) 1)
             ((evenp n) (square (power x (/ n 2))))
             (:else (* x (power x (- n 1))))))
    
    (power 2 10)
    Kent OHASHI
    @lagenorhynque
    (def atom? (complement sequential?))
    
    (defn count-atoms [expr]
      (cond
        (atom? expr) 1
        (empty? expr) 0
        :else (+ (count-atoms (first expr))
                 (count-atoms (rest expr)))))
    Satoshi Imai
    @masatoi
    ズルするとこうなります
    (defun count-atom (lst)
      (count-if #'atom lst))
    七誌
    @7shi_twitter

    次回は4/4(水) 20:00からです。
    https://jitsucl.connpass.com/event/82964/
    フランドン畜舎内 ヨークシャイヤ
    @furandon_pig_twitter
    今読んでいるところのLISPコードは↓ですかね。
    https://github.com/norvig/paip-lisp/blob/master/lisp/simple.lisp

    七誌
    @7shi_twitter
    次回は4/18(水) 20:00です。 https://jitsucl.connpass.com/event/84345/
    七誌
    @7shi_twitter
    会場の都合により一週間延期とさせていただきました。
    次回は4/25(水) 20:00です。 https://jitsucl.connpass.com/event/85528/
    Kent OHASHI
    @lagenorhynque
    CL-USER> (let ((v 42))
               v)
    42
    CL-USER> ((lambda (v) v) 42)
    42
    Satoshi Imai
    @masatoi
    ちなみにここまでのコードはここです
    Kent OHASHI
    @lagenorhynque
    ;; Exercise 2.3
    (def simple-japanese-grammar
      '((sentence -> (subject predicate))
        (subject -> (noun-phrase ParticleForSubject))
        (predicate -> (noun-phrase ParticleForObject Verb))
        (noun-phrase -> (NounModifier Noun))
        (NounModifier -> その ある)
        (Noun -> 男 ボール 女 テーブル)
        (ParticleForSubject -> が)
        (ParticleForObject -> を)
        (Verb -> 打った 取った 見た 好んだ)))
    
    (reset! grammar simple-japanese-grammar)
    
    (generate 'sentence)
    > (generate 'sentence)
    (ある テーブル が その 女 を 好んだ)
    七誌
    @7shi_twitter
    七誌
    @7shi_twitter
    5月は9と23です。
    明日は渋谷LISPです。 https://lisp.connpass.com/event/84395/

    七誌
    @7shi_twitter
    次回は5/9(水) 20:00からです。 https://jitsucl.connpass.com/event/86596/
    七誌
    @7shi_twitter
    Common Lisp the Language, 2nd Edition
    https://www.cs.cmu.edu/Groups/AI/html/cltl/cltl2.html
    Kent OHASHI
    @lagenorhynque
    クロージャの典型例といえばカウンターでしょうか。
    CL-USER> (defun make-counter (n) 
               (lambda ()
                 (incf n)))
    MAKE-COUNTER
    CL-USER> (defparameter c (make-counter 0))
    C
    CL-USER> (funcall c)
    1
    CL-USER> (funcall c)
    2
    CL-USER> (defparameter c2 (make-counter 0))
    C2
    CL-USER> (funcall c2)
    1
    Kent OHASHI
    @lagenorhynque
    七誌
    @7shi_twitter
    Satoshi Imai
    @masatoi
    ((lambda (x) ((lambda (y) (+ x y)) (* x x))) 6)
    Kent OHASHI
    @lagenorhynque
    ;; Exercise 3.1
    ((fn [x]
       ((fn [y]
          (+ x y))
        (* x x)))
     6)
    七誌
    @7shi_twitter
    hylang