J:一周目(中)

NB. 一周目本来应该在7日内结束的,无奈这周事情有点多,只好延后一天了 = = 

之前写完一周目上篇的时候也顺便往后开了下,其实 checkPoint ABC 都不是很难的样子。于是原本说是到B就可以的,现在有点贪心不足想往后赶到E。不过也就需要花更多的时间了...

另外这里其实有个问题,就是 J Primer 是按照 J 60x写的,现在已经 J80x了,所以有些操作会有些对不上。不过影响不大,下文也会提供些折中的办法。

先进入正题,看下 checkpoint B,不对,先回顾下上篇:

- 简单说,J跟常规编程语言的差别主要体现在:没有(严格的)运算优先级,(从右往左)顺序执行
- 然后,checkPoint A要求搞懂的几个动词:+:    *:    -:    %:   NB. 好吧,老实说上篇我把这个环节忽略了...不过第一遍的话,也没啥关系啦

然后看下B部分的目录:

Numeric constant    这一节引入了列表,和传统编程语言没啥差别,只是少了方括号
String    只能用单引号框字符串,如果要转义字符串内的单引号,敲两个就好了。
Word formation    这招后面应该比较管用,用 ;: 来分割语句,初学必备(记得用单引号框起来
Space    讲了什么时候该有空格什么时候可以省略,其实初学的话,全部打上比较好看清吧
Precedence    讲优先级的,原话:Remember: there is no verb precedence.
Parentheses    括号的用法和常规语音类似
Order of evaluation    求值顺序:no verb precedence and right-to-left evaluation.
Verb definition    讲动词(函数)定义的方法,第一感觉会比较奇葩
Monad/dyad defined    同上,(不完全)详解单子和双子的定义方法
Script file    教你怎么写文件这里开始容易出现版本上的差异
Local    解释局部变量 =.
Global    解释全局变量 =:
Debug global    讲了一个很简单粗暴的使用全局变量的调试技巧
When =.and =:are alike    简单解释了局部和全局的差别
When they aren't    同理。
Locale    A locale is a set(集合) of global names.
z locale    The z locale is the parent locale of all other locales.
Script load    如何调用脚本
Checkpoint B

At this point you should understand:

- a text file that is a source of sentences is called a script file
- a script file defines global names
- how to create a new temporary script file
- how to save a temporary script file as a permanent file
- how to run a script file to execute its sentences
- how to define a verb in a script file
- how to define the monadic and dyadic cases of a verb
- the difference between=.and=:
- the difference between local and global
- that a locale is a set of global names
- that there can be more than one locale
- that the base locale is the one you normally work with

Check your understanding by doing the following exercises:

- create a new temporary script file
- in the script define square as a monad that uses *: to square its argument
- save the script in the user directory with the name square.ijs
- run the script and test the verb square
- close J, restart, use Run|File to run user\square.ijs and test it

其实checkpointB的内容也不少,主要就是明白怎么写脚本,定义动词,以及locale的用法。

然后是下一部分:

Debug - step through    步进调试 dbss, dbr, dbrun
Debug - an error    dbjump
Comparative    比较符 =    <    <:    >    >:
Control structure    控制结构  if.  /  do.  /  else.  /  elseif.    try.    while.  /  whilst.    for.  /  for_i.    select.  / case.  /  fcase.    end.
Checkpoint C

At this point you should understand:

- that load 'debug'  loads debug utilities
- the general idea of verb debugging
- how control words create control structures by grouping sentences into blocks
- what the T block test result is
- how the test result determines which B block to execute
- how the test result determines when control structure execution is finished

Check your understanding by doing the following exercises:

- debug step through your convert verb
- create a temporary script file and define a verb calledconvthat is similar toconvert, but insists on a 'f' argument to do the conversion to Fahrenheit and gives a string result indicating there was an error if the left argument is neither 'c' nor 'f'. Hint: use the control structure sketched out here:

if. x = 'c' do. ...
    elseif. x = 'f' do. ...
    elseif. 1 do. 'left arg not c or f'
end.

or try aselect.structure.

- create a temporary script file and define a dyad called plus that adds its left argument to its right. But, if there is an error, it should give a string result. Hints: use dyad :0; 4 plus 9should return 13;'a' plus 9should return your error string (perhaps,'there was an error'); use atry.control structure to catch the error and give the string result.

cpC的内容也不难懂,暂时没啥要总结的,回去做下练习题就好。然后是cpD:

Adding lists  基本列表操作  {     ,     #    
J way of adding lists
    列表操作的正确打开方式(APL风格)
A few more primitives    引入更多运算  i.    $     ?     ^     o. 
Plot
  这个很方便,jhs开出来的网页版jijx也可以用。三角函数可能有点不好懂
Plot locale  以load 'plot'为例带你回顾下前面的locale
Print precision    输出精度控制
Inexact numbers   继续浮点数精度的问题
Tolerance     关于精度误差的容错
Checkpoint D

At this point you should understand:
 - primitives work with lists
 - your own verbs work with lists
 - how to use several new verbs
 - how to use the plot facility
 - comparatives such as = that give numeric 0 and 1 results

Check your understanding by doing the following exercises:
 - look up the J Dictionary definitions of the integers, shape, roll, power, and circle verbs; in most cases only a part of their capabilities have been introduced, so you will have to read the definitions carefully to be able to ignore the parts not yet relevant, and to pick out the parts that are
 - experiment with the new primitives

感觉E部分比较多,可以当作回顾性内容,所以把原定一篇搞定的下篇分成中下两篇了。

这篇知识点不少,需要多加练习,不然容易忘。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,219评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,363评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,933评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,020评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,400评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,640评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,896评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,597评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,327评论 1 244
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,581评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,072评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,399评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,054评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,849评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,672评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,585评论 2 270

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,305评论 5 6
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 2,652评论 0 0
  • 按照预定计划,前4千米配速在5'30''至6'之间,后1千米在4'30''至5'30'',最后实在提不起速了,跑表...
    podrunner阅读 331评论 1 1
  • 她躺着 先是听见月光碎在院子里 接着她捧不住夜晚 寂寞是大山沉沉的声音 雪落在街头 世界如此喧嚣
    光白阅读 340评论 2 6