J:一周目(中)

2015-07-17  本文已影响97人  NTFS

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部分比较多,可以当作回顾性内容,所以把原定一篇搞定的下篇分成中下两篇了。

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

上一篇下一篇

猜你喜欢

热点阅读