Before
LISPs
Just Part of the Past
〜 #15 case sensitive quote 〜
car => CAR
READ as
(cdr '(Common Lisp))
=>
(CDR (QUOTE (COMMON LISP)))
⇓
(LISP)
EVAL to
(cdr '(|Common| Lisp))
=>
(CDR (QUOTE (|Common| |Lisp|)))
⇓
(|Lisp|)
readcase
● :UPCASE cAr => CAR
● :DOWNCASE cAr => |car|
● :PRESERVE cAr => |cAr|
● :INVERT cAr => |cAr|
– cdr => CDR
– CDR ...
Case Sensitive Quote
● :PRESERVEで1回だけREADして、
結果をQUOTEして返す
● ^a => '|a|
● ^(a b c) => '(|a| |b| |c|)
●
たまに欲しい
– 設定ファイルを書き出す...
:PRESERVE or :INVERT, or ...
●
標準のオペレータ名は全て大文字
– :INVERTが一番現実的
● 他言語のコードをS式で埋め込む際は:INVERTでも
不十分
– キーワードは全小文字が圧倒的に多い
●
意地悪な...
let sqF = fun x → x * x in sqF 2
● (eval-ml ; eval-my-language
(let (sqF (fun (x) (* x x)))
(sqF 2)))
● 望ましいREAD結果
(EVAL-M...
let sqF = fun x → x * x in sqF 2
● (eval-ml
(let (sqF (fun (x) (* x x)))
(sqF 2)))
=>
(EVAL-ML
(LET (SQF (FUN (X) (* X X))...
let sqF = fun x → x * x in sqF 2
● (eval-ml
(|let| (|sqF| (|fun| (|x|) (* |x| |x|)))
(|sqF| 2)))
=>
(EVAL-ML
(let (sqF (fu...
let sqF = fun x → x * x in sqF 2
● (eval-ml
(let (|sqF| (fun (|x|) (* |x| |x|)))
(|sqF| 2)))
=>
(EVAL-ML
(LET (sqF (FUN (x...
let sqF = fun x → x * x in sqF 2
● (eval-ml
|(let (sqF (fun (x) (* x x)))
(sqF 2))|)
=>
(EVAL-ML
|(let (sqF (fun (x) (* x ...
let sqF = fun x → x * x in sqF 2
● (eval-ml
^(let (sqF (fun (x) (* x x)))
(sqF 2)))
=>
(EVAL-ML
'(|let| (|sqF| (|fun| (|x|...
Case Sensitive Read
● :PRESERVEで1回だけREADする
● !a => |a|
● !(a b c) => (|a| |b| |c|)
● (EQ '!x ^x) T⇓
let sqF = fun x → x * x in sqF 2
● (eval-ml
!(let (sqF (fun (x) (* x x)))
(sqF 2)))
=>
(EVAL-ML
(|let| (|sqF| (|fun| (|x|)...
文字は有限な資源です
Prochain SlideShare
Chargement dans…5
×

Before LISPs Just Part of the Past ~ #15 case sensitive quote ~

302 vues

Publié le

A consideration about reader behaviour in Common Lisp.

Publié dans : Logiciels
0 commentaire
0 j’aime
Statistiques
Remarques
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Aucun téléchargement
Vues
Nombre de vues
302
Sur SlideShare
0
Issues des intégrations
0
Intégrations
57
Actions
Partages
0
Téléchargements
2
Commentaires
0
J’aime
0
Intégrations 0
Aucune incorporation

Aucune remarque pour cette diapositive

Before LISPs Just Part of the Past ~ #15 case sensitive quote ~

  1. 1. Before LISPs Just Part of the Past 〜 #15 case sensitive quote 〜
  2. 2. car => CAR READ as
  3. 3. (cdr '(Common Lisp)) => (CDR (QUOTE (COMMON LISP))) ⇓ (LISP) EVAL to
  4. 4. (cdr '(|Common| Lisp)) => (CDR (QUOTE (|Common| |Lisp|))) ⇓ (|Lisp|)
  5. 5. readcase ● :UPCASE cAr => CAR ● :DOWNCASE cAr => |car| ● :PRESERVE cAr => |cAr| ● :INVERT cAr => |cAr| – cdr => CDR – CDR => cdr
  6. 6. Case Sensitive Quote ● :PRESERVEで1回だけREADして、 結果をQUOTEして返す ● ^a => '|a| ● ^(a b c) => '(|a| |b| |c|) ● たまに欲しい – 設定ファイルを書き出すのでcase-sensitiveな トークンが必要、とか
  7. 7. :PRESERVE or :INVERT, or ... ● 標準のオペレータ名は全て大文字 – :INVERTが一番現実的 ● 他言語のコードをS式で埋め込む際は:INVERTでも 不十分 – キーワードは全小文字が圧倒的に多い ● 意地悪な例を、現実に見つけることができる – ex) 大文字アルファベットで始まるのはクラス名 – ex) 変数は小文字で始まるけど大文字を含んでも良い
  8. 8. let sqF = fun x → x * x in sqF 2 ● (eval-ml ; eval-my-language (let (sqF (fun (x) (* x x))) (sqF 2))) ● 望ましいREAD結果 (EVAL-ML (|let| (|sqF| (|fun| (|x|) (* |x| |x|))) (|sqF| 2))) ● 関数やマクロでは実現できない
  9. 9. let sqF = fun x → x * x in sqF 2 ● (eval-ml (let (sqF (fun (x) (* x x))) (sqF 2))) => (EVAL-ML (LET (SQF (FUN (X) (* X X))) (SQF 2))) ● READ時の制御にはreader macro
  10. 10. let sqF = fun x → x * x in sqF 2 ● (eval-ml (|let| (|sqF| (|fun| (|x|) (* |x| |x|))) (|sqF| 2))) => (EVAL-ML (let (sqF (fun (x) (* x x))) (sqF 2))) ● めんどい.
  11. 11. let sqF = fun x → x * x in sqF 2 ● (eval-ml (let (|sqF| (fun (|x|) (* |x| |x|))) (|sqF| 2))) => (EVAL-ML (LET (sqF (FUN (x) (* x x))) (sqF 2)) ● ||の挿入回数は本質的に減っていない
  12. 12. let sqF = fun x → x * x in sqF 2 ● (eval-ml |(let (sqF (fun (x) (* x x))) (sqF 2))|) => (EVAL-ML |(let (sqF (fun (x) (* x x))) (sqF 2))|) ● 1つの要素になってしまったので全然ダメ
  13. 13. let sqF = fun x → x * x in sqF 2 ● (eval-ml ^(let (sqF (fun (x) (* x x))) (sqF 2))) => (EVAL-ML '(|let| (|sqF| (|fun| (|x|) (* |x| |x|))) (|sqF| 2))) ● QUOTEが.
  14. 14. Case Sensitive Read ● :PRESERVEで1回だけREADする ● !a => |a| ● !(a b c) => (|a| |b| |c|) ● (EQ '!x ^x) T⇓
  15. 15. let sqF = fun x → x * x in sqF 2 ● (eval-ml !(let (sqF (fun (x) (* x x))) (sqF 2))) => (EVAL-ML (|let| (|sqF| (|fun| (|x|) (* |x| |x|))) (|sqF| 2)))
  16. 16. 文字は有限な資源です

×