每种语言都有它特别的地方,对于JavaScript来说,使用var就可以声明任意类型的变量,这门脚本语言看起来很简单,然而想要写出优雅的代码却是需要不断积累经验的。本文利列举了JavaScript初学者应该注意的七个细节,与大家分享。 (1)简化代码JavaScript定义对象和数组非常简单,我们想要创建一个对象,一般是这样写的: ?
1
2
3
4
5 var car = new Ob...
分类:
编程语言 时间:
2015-02-28 11:33:03
阅读次数:
179
# 读取多元统计分析数据到R
wine
# 绘制多元统计数据
# 矩阵散点图
# 一种常见的方法是使用散点图画出多元统计数据,展现出所有变量两两之间的散点图。
# 我们可以使用R中的“car”包里的“scatterplotMatrix()”函数来实现。
library(car)
scatterplotMatrix(wine[2:6])
# 组群标注数据点的散点图
plot(win...
分类:
编程语言 时间:
2015-02-27 18:25:36
阅读次数:
222
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to it...
分类:
其他好文 时间:
2015-02-27 17:07:10
阅读次数:
147
Problem with a car: A customer towned to my shop a Mercedes' C180 W202 year 1997 with no working keys. The key itself won't turn in EIS and wont unloc...
分类:
其他好文 时间:
2015-02-26 18:05:33
阅读次数:
506
There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[...
分类:
其他好文 时间:
2015-02-24 00:46:50
阅读次数:
228
??
练习2.42
这道题曾经在C#中写过,但是写出来的代码却没有Lisp中的朴素。用了一大堆的数组和for循环。但是在这里,用car、cdr来构造就行了。
我们按书中给出的步骤来一步一步求解这个问题。首先是棋局,就按书上的示意图,从上往下的来排皇后的位置。诸如此时书中皇后的位置为:’(6 3 1 7 5 8 2 4)。
然后就是过程adjoin-position。rest...
分类:
其他好文 时间:
2015-02-23 09:46:38
阅读次数:
172
??
练习2.39
通过前一习题的类比相信已经知道了fold-left和fold-right的内在意义,本题中要求的逆序数可以用cons来构造。具体为,先将list的第一个元素取出用(cons
(car list) ‘() )构造,接着第二个、第三个……用(cons
…… (cons (car (car list) ) (cons (carlist) ‘())))。当然了,在这个...
分类:
其他好文 时间:
2015-02-23 09:46:37
阅读次数:
121
??
练习2.29
这种题,还有之前的那个rectangle的题目,对于变量、函数等的命名简直要让人疯掉。先来写出题目中的left-branch和right-branch吧。
(define (left-branch mobile)
(car mobile))
(define (right-branch mobile)
(cadr mobile))
...
分类:
其他好文 时间:
2015-02-22 14:37:40
阅读次数:
141
??
练习2.46
这道题就是彻头彻尾的”构造”了。直接上代码吧。
(define (make-vect xcor ycor) (listxcor ycor))
(define (xcor-vect v) (car v))
(define (ycor-vect v) (cdr v))
(define (add-vect first-vectsecond-vect...
分类:
其他好文 时间:
2015-02-22 14:37:05
阅读次数:
133
??
练习2.4
直接运用对比的技巧就可以猜测出相应的cdr表示如下:
(define (cdr z)
(z (lambda (p q) q)))
但我们还是要按照题中要求用代换模型来检验。先来检验car的。
(car (cons 0 1))
(car (lambda (m) (0 1)))
((lambda (z) (z (lambda (p...
分类:
其他好文 时间:
2015-02-17 21:06:55
阅读次数:
144