tacit-programming

J: Tacit adverb of Newton's method

感情迁移 提交于 2020-01-03 09:10:10
问题 I've found in 'addons/math/misc/brent.ijs' implementation of Brent's method as an adverb. I would like to build a Newton's method as an adverb too but it's much harder than building tacit verbs. Here is a explicit version of Newton's iteration: newton_i =: 1 : '] - u % u d.1' With such usage: 2&o. newton_i^:_ (1) NB. (-: 1p1) must be found 1.5708 2 o. 1.5708 NB. after substitution we get almost 0 _3.67321e_6 And of course, for convenience: newton =: 1 : 'u newton_i^:_' What's a tacit

How to refactor this in J?

不想你离开。 提交于 2019-12-24 20:32:47
问题 Here is a different approach for the Project Euler #1 solution: +/~.(3*i.>.1000%3),5*i.>.1000%5 How to refactor it? 回答1: [:+/@~.@,3 5([*i.@>.@%~)] usage example: f =: [:+/@~.@,3 5([*i.@>.@%~)] f 1000 or +/~.,3 5([*i.@>.@%~)1000 %~ = 4 : 'y % x' i.@>.@%~ = 4 : 'i. >. y % x' [*i.@>.@%~ = 4 : 'x * i. >. y % x' 3 5([*i.@>.@%~)] = 3 : '3 5 * i. >. y % 3 5' [:+/@~.@,3 5([*i.@>.@%~)] = 3 : '+/ ~. , 3 5 * i. >. y % 3 5' 回答2: +/(#~ ( (0= 3| ]) +. (0 = 5 |]) )) 1+i.999 0 = ( 3 | ]) uses (twice) the

Tacit function composition in Haskell

半城伤御伤魂 提交于 2019-12-22 02:00:59
问题 Say I have a mean function defined like so: mean xs = sum xs / (fromIntegral $ length xs) but I want it in some tacit form, like this: mean = sum / (fromIntegral . length) Is there a built-in Haskell way to do something along these lines without having to build up my own tacit function (something like this): tacit :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c tacit a b c i = a (b i) (c i) In this form, the function looks like this: mean = tacit (/) sum (fromIntegral . length) but it

How to refactor this in J?

£可爱£侵袭症+ 提交于 2019-12-13 16:33:09
问题 My newbie solution to Project Euler #1 +/((0=3|1+i.1000-1) +. (0=5|1+i.1000-1)) * (1+i.1000-1) I know that this can be refactored, and transformed into a function, i don't know how to do it, and I would have to read all the labs to learn it. 回答1: It isn't necessary to "handle zero" because adding zero won't change the answer so you can just use i. to generate your list of numbers below 1000, for example: i. 10 0 1 2 3 4 5 6 7 8 9 J works best with arrays so you should be able to ask for the

Why does this point-free F# function behave differently from the non-point-free version?

扶醉桌前 提交于 2019-12-12 16:24:54
问题 Consider the following F#:- type TestClass() = let getValFromMap m k = Map.find k m let addToMap map k i = map |> Map.add k i let mutable someMap : Map<string,int> = Map.empty let getValFromMapPartial key = getValFromMap someMap key let getValFromMapPartialAndTacit = getValFromMap someMap member this.AddThenGet() = someMap <- addToMap someMap "A" 10 let value = getValFromMapPartial "A" printfn "Value from partial = %i" value // prints out let value = getValFromMapPartialAndTacit "A" // throws

Best strategies for reading J code

梦想与她 提交于 2019-12-10 02:21:29
问题 I've been using J for a few months now, and I find that reading unfamiliar code (e.g. that I didn't write myself) is one of the most challenging aspects of the language, particularly when it's in tacit. After a while, I came up with this strategy: 1) Copy the code segment into a word document 2) Take each operator from (1) and place it on a separate line, so that it reads vertically 3) Replace each operator with its verbal description in the Vocabulary page 4) Do a rough translation from J

Best strategies for reading J code

拜拜、爱过 提交于 2019-12-05 00:42:42
I've been using J for a few months now, and I find that reading unfamiliar code (e.g. that I didn't write myself) is one of the most challenging aspects of the language, particularly when it's in tacit. After a while, I came up with this strategy: 1) Copy the code segment into a word document 2) Take each operator from (1) and place it on a separate line, so that it reads vertically 3) Replace each operator with its verbal description in the Vocabulary page 4) Do a rough translation from J syntax into English grammar 5) Use the translation to identify conceptually related components and

Tacit function composition in Haskell

柔情痞子 提交于 2019-12-04 23:53:21
Say I have a mean function defined like so: mean xs = sum xs / (fromIntegral $ length xs) but I want it in some tacit form, like this: mean = sum / (fromIntegral . length) Is there a built-in Haskell way to do something along these lines without having to build up my own tacit function (something like this): tacit :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c tacit a b c i = a (b i) (c i) In this form, the function looks like this: mean = tacit (/) sum (fromIntegral . length) but it feels like there might be a way to avoid having to use an explicit function such as this. I'm just

Tacit programming in Lisp

眉间皱痕 提交于 2019-12-04 16:20:09
问题 Is it possible to use/implement tacit programming (also known as point-free programming) in Lisp? And in case the answer is yes, has it been done? 回答1: This style of programming is possible in CL in principle, but, being a Lisp-2, one has to add several #' s and funcall s. Also, in contrast to Haskell for example, functions are not curried in CL, and there is no implicit partial application. In general, I think that such a style would not be very idiomatic CL. For example, you could define

How to filter a list in J?

吃可爱长大的小学妹 提交于 2019-11-30 06:18:49
I'm currently learning the fascinating J programming language, but one thing I have not been able to figure out is how to filter a list. Suppose I have the arbitrary list 3 2 2 7 7 2 9 and I want to remove the 2s but leave everything else unchanged, i.e., my result would be 3 7 7 9 . How on earth do I do this? Yasir Arsanukaev The short answer 2 (~: # ]) 3 2 2 7 7 2 9 3 7 7 9 The long answer I have the answer for you, but before you should get familiar with some details. Here we go. Monads, dyads There are two types of verbs in J: monads and dyads . The former accept only one parameter, the