惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
J
Java Code Geeks
G
Google Developers Blog
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
L
LangChain Blog
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
Vercel News
Vercel News
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
Y
Y Combinator Blog
博客园_首页
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
A
About on SuperTechFans
B
Blog
Microsoft Security Blog
Microsoft Security Blog

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟
Squeak 备忘
种瓜 · 2020-11-18 · via 夜行人

文章目录

日常备忘。

由于 Pharo 派生自 Squeak,所以很多资源是可以共用的

一些材料

语法备忘

Terse Guide to Squeak

Array(list)

将 list 视为不可变的结构(历史不可变),每次都生成新的.

发挥 LISP 精神,灵活操控 list。

只使用少量操作符:

  • atom
  • eq (x=y)
  • car ([:x |x at: 1.])
  • cdr ([:x |x copyFrom: 2 to: x size.])
  • cons ([:x :y|Array with: x with: y])
  • cond (ifTrue:)
1
2
3
4
5
6
car := [:x |x at: 1.].
cdr := [:x |x copyFrom: 2 to: x size.].
cons:= [:x :y|Array with: x with: y].
car value: #(1 2 3 ).
cdr value: #(1 2 3 ).
cons value: #(1 2 3 ) value: 1.

Smalltalk 源码不是S表达式,尽可能将 list 用作 S表达式, 灵活使用 block, 诸如: #([:x |x at:1.], 1 2 3)

1
2
y := {[:x |x at:1.] . 1 . 2 . 3}.
(car value: y) value: (cdr value: y). "1"

由于 Smalltalk 和LISP 一样(Alan Kay是LISP忠实粉丝)是一门关注late binding的语言,所以 list 中可以携带各种东西!

1
2
3
"receiver perform: message."
y := {'factorial' asSymbol . 5 . 6 . 7}.
(car value: (cdr value: y)) perform: (car value: y). "120 (5x4x3x2x1)"

create

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
x := #(4 3 2 1). 

"Array 长度固定"
x := Array with: 5 with: 4 with: 3 with: 2.                 "create array with up to 4 elements"

x := Array new: 4.                                          "allocate an array with specified size"
x                                                           "set array elements"
   at: 1 put: 5;
   at: 2 put: 4;
   at: 3 put: 3;
   at: 4 put: 2.

a := 'hi'
x := {a . 1 . 2} "a 将被解析。 #(a 1 2)->a是symbol"

query && utils

1
2
3
4
5
x isEmpty.
x size.
x includes: 3.
x select: [:a | a > 2].
x do: [:a | Transcript show: a printString; cr].            "iterate over the array"

Dictionaries

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
x := Dictionary new.
x at: #e put: 3.
x at: 'key1' put: 3.
x includesKey: #a.
x keys.
x values.
x do: [:a | Transcript show: a printString; cr]        "iterate over the values collection"
x keysDo: [:a | Transcript show: a printString; cr].   "iterate over the keys collection"
x keysAndValuesDo: [:aKey :aValue | Transcript         "iterate over keys and values"
   show: aKey printString; space;
   show: aValue printString; cr].
x select: [:a | a > 2].       "return collection(dict) of elements that(value) pass test"

Smalltalk globals keys

环境介绍(视频)

Squeak from the very start

常用

Morphic

Morphic

late binding

在持续积累 late binding 相关技能

Dynamic Message Calling/Compiling

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"unary message"
receiver := 5.
message := 'factorial' asSymbol.
result := receiver perform: message.
result := Compiler evaluate: ((receiver storeString), ' ', message).
result := (Message new setSelector: message arguments: #()) sentTo: receiver.

"binary message"
receiver := 1.
message := '+' asSymbol.
argument := 2.
result := receiver perform: message withArguments: (Array with: argument).
result := Compiler evaluate: ((receiver storeString), ' ', message, ' ', (argument storeString)).
result := (Message new setSelector: message arguments: (Array with: argument)) sentTo: receiver.

"keyword messages"
receiver := 12.
keyword1 := 'between:' asSymbol.
keyword2 := 'and:' asSymbol.
argument1 := 10.
argument2 := 20.
result := receiver
   perform: (keyword1, keyword2) asSymbol
   withArguments: (Array with: argument1 with: argument2).
result := Compiler evaluate:
   ((receiver storeString), ' ', keyword1, (argument1 storeString) , ' ', keyword2, (argument2 storeString)).
result := (Message new
      setSelector: (keyword1, keyword2) asSymbol
      arguments: (Array with: argument1 with: argument2))
   sentTo: receiver.

连接

与外部系统通信

OSC

Adatper Squeak

在Squeak中, 下载 OSC : OSC-SimonHolland, 之后拖到 Squeak 桌面,加载使用即可。

1
2
3
4
5
(OSCMessage for: {'/eim/osc' . 1}) sendTo: #[127 0 0 1] port: 12361. 

(OSCMessage for: {'/eim/osc' . 0}) sendTo: #[127 0 0 1] port: 12361.

(OSCMessage for: {'/eim/osc' . -1}) sendTo: #[127 0 0 1] port: 12361. 

Scratch Client

Adapter Etoys

解析工具

参考