我試圖學習J和我使用的是書上說這是定義一個一元函數爲什麼這個J功能不能運行?
function =: 3:0 function statements
所以我遵循了這一格式,並寫了摺疊代碼的正確方法。你能告訴我這是爲什麼拋出一個語法錯誤,當我嘗試輸入稱呼它,但如果我只是叫p將其返回3
h=:>:@[email protected]<[email protected]: :[: NB. gets all integers less than half of the input :[: forces error if used dyadicly
d=:(0&=|)~ h :[: NB. gets list where if one is set that index from h was a factor of the input y :[: forces error if used dyadicly
p=: 3:0 NB. tells us p is a monadic function
t =: d y
a =: i. 1
while. 1<#t
if. t~:0
a =: a, #t
end.
t=: _1 }. t NB. found first mistake wrong bracket but fixing that doesn't fix it
end.
a*1
)
NB. p gets a list of all integers that are factors of y
p 4
| syntax error
| p 4
p
3
NB. h and d run fine
h 4
1 2
h 7
1 2 3
d 7
1 0 0
d 4
1 1
J不是一種函數式編程語言。它是一種功能級編程語言。 (請參閱維基百科關於函數級編程的文章,以討論其差異。) – 2009-11-28 02:44:03