Question of begginer

Received: by 10.100.231.16 with SMTP id d16mr69404anh.20.1219186650645; Tue,
19 Aug 2008 15:57:30 -0700 (PDT)
Date: Tue, 19 Aug 2008 15:57:30 -0700 (PDT)
X-IP: 92.100.95.75
User-Agent: G2/1.0
X-Google-Token: 0iIM3wwAAACvwUgMNHW6igc3nKhcOnSQ
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.16)
Gecko/20080702 Firefox/2.0.0.16,gzip(gfe),gzip(gfe)
Message-ID: <763b8dd1-d05b-4761-bd2c-b7cc88f4d191@y38g2000hsy.googlegroups.com>
Subject: Question of begginer
From: victor79
To: “Kdb+ Personal Developers”
X-Google-Approved: simon.garland@gmail.com via email at 2008-08-20 14:43:07

I try understand expression:
ini:0:`test.ini
ini_tree:{r:(0 1) _ x; r[1]:{x[0]:(-1 _ x[0]); x}'{(0,1+x?“=”)
x}‘r[1]; r}’(&{~~((1+x?“[”)
x)?“]”}'ini2) _ ini2:{x[&{~1>#x}'x]}[ini]
and convert it to K4. What means {…} without in &{~1>#x}'x ?
and can anybody help convert this exact as above only for K4? (this is
parser for ini file)

On Wed, Aug 20, 2008 at 6:57 AM, victor79 wrote:

> I try understand expression:
> ini:0:`test.ini
> ini_tree:{r:(0 1) _ x; r[1]:{x[0]:(-1 _ x[0]); x}'{(0,1+x?“=”)
> x}‘r[1]; r}’(&{~~((1+x?“[”)
x)?“]”}'ini2) _ ini2:{x[&{~1>#x}'x]}[ini]
> and convert it to K4. What means {…} without in &{~1>#x}'x ?
> and can anybody help convert this exact as above only for K4? (this is
> parser for ini file)

{} marks a function definition, regardless of how it’s later invoked.
in this case, it’s being invoked once for each x. (apostrophe is the
adverb “each”.)

what language is your sample in?

Aaron Davies
aaron.davies@gmail.com


On Wed, Aug 20, 2008 at 6:57 AM, victor79 wrote:
>
>> I try understand expression:
>> ini:0:`test.ini
>> ini_tree:{r:(0 1) _ x; r[1]:{x[0]:(-1 _ x[0]); x}'{(0,1+x?“=”)
>> x}‘r[1]; r}’(&{~~((1+x?“[”)
x)?“]”}'ini2) _ ini2:{x[&{~1>#x}'x]}[ini]
>> and convert it to K4. What means {…} without in &{~1>#x}'x ?
>> and can anybody help convert this exact as above only for K4? (this is
>> parser for ini file)
>
> {} marks a function definition, regardless of how it’s later invoked.
> in this case, it’s being invoked once for each x. (apostrophe is the
> adverb “each”.)
>
> what language is your sample in?

incidentally your code is perfectly fine k4, with just one bug: k4
parsing rules make it hard to put an underscore in a variable name.
(it’s interpreted as the “drop” operator.) change “ini_tree” to
“iniTree” and it will work fine.

Aaron Davies
aaron.davies@gmail.com


User-Agent: G2/1.0X-Google-Token: Cyt3wAwAAADJp_f0bGuXmpd8TMSAGWYzX-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16,gzip(gfe),gzip(gfe)Message-ID: Subject: Re: Question of begginerFrom: victor79 To: “Kdb+ Personal Developers” X-Google-Approved: simon.garland@gmail.com via email at 2008-08-21 06:11:50I have kdb+ 2.4 from code.kx.com. In this version don’t work previsionexpression.q){x[&{~1>#x}‘x}[(“as”;“qwe”;“a”)]’}q)k){x[&{~1>#x}‘x}[(“as”;“qwe”;“a”)]’}if get examples from http://en.wikipedia.org/wiki/K_(programming_language)its don’t evalutes in q) mode nor k). May be in 2.3 this work, but notin 2.4.(I don’t search version where it work, i simply study.)Prevision sample while wait, can you help me recognize `$‘’'$“asdf”(it work, but I don’t understand it. From http://www.nsl.com/k/kparse.k, second line)?

On Thu, Aug 21, 2008 at 12:36 PM, victor79 wrote:

> I have kdb+ 2.4 from code.kx.com. In this version don’t work prevision
> expression.

as i said, your ini parser is fine, except for the name of the
variable, which gives k4 problems q wouldn’t have

here’s the code running over my windows boot.ini (copied and renamed
as test.ini):

> cat test.ini
[boot loader]
timeout0
default=multi(0)disk(0)rdisk(0)partition(1)WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)WINDOWS=“Microsoft Windows XP
Professional” /noexecute=optin /fastdetect
> q
KDB+ 2.4 2008.07.22 Copyright (C) 1993-2008 Kx Systems
l64/ 8(8)core 32135MB

q)k)ini:0:test.ini;iniTree:{r:(0 1) _ x; r[1]:{x[0]:(-1 _ x[0]);<br>x}'{(0,1+x?"=") _x}'r[1]; r}'(&amp;{~~((1+x?"[")_ x)?"]"}'ini2) _<br>ini2:{x[&amp;{~1&gt;#x}'x]}[ini]<br>q)iniTree<br>,"[boot loader]"<br><br>(("timeout";"30");("default";"multi(0)d..<br>"[operating systems]"<br><br>"multi(0)disk(0)rdisk(0)partition(1)\W..<br>q)show each iniTree;<br>,"[boot loader]"<br>(("timeout";"30");("default";"multi(0)disk(0)rdisk(0)partition(1)\WINDOWS"))<br>"[operating systems]"<br>"multi(0)disk(0)rdisk(0)partition(1)\WINDOWS" ""Microsoft Windows XP<br>Professional" /noexecute=optin /fastdetect"<br><br>&gt; q){x[&amp;{~1&gt;#x}'x}[("as";"qwe";"a")]<br>&gt; '}<br>&gt; q)k){x[&amp;{~1&gt;#x}'x}[("as";"qwe";"a")]<br>&gt; '}<br><br>yes, you'll note the unmatched left brace at the start of the<br>expression. i think it's supposed to be<br>k){x[&amp;{~1&gt;#x}'x]}[("as";"qwe";"a")]:<br><br>q)k){x[&amp;{~1&gt;#x}'x]}[("as";"qwe";"a")]<br>"as"<br>"qwe"<br>"a"<br><br>&gt; if get examples from http://en.wikipedia.org/wiki/K_(programming_language)<br>&gt; its don't evalutes in q) mode nor k). May be in 2.3 this work, but not<br>&gt; in 2.4.<br>&gt; (I don't search version where it work, i simply study.)<br><br>i think that's mostly k3, some of them need a little translation. e.g.<br>here's the prime tester over 3-100:<br><br>q)k){y@&amp;x'y}[{&amp;/x .q.mod/:2_!x}]3_!100<br>3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97<br><br>(int!int was apparently mod in k3; in k4, it's a function written in k<br>and defined in the file q.k)<br><br>&gt; Prevision sample while wait, can you help me recognize $‘’‘$“asdf”
> (it work, but I don’t understand it. From http://www.nsl.com/k/kparse.k
> , second line)?

bear in mind that i’m executing this in k4; i make no guarantees that
this is what this code would do in k3

i also have no idea what the point of this is, as i don’t understand
lines 5 or 6 of the file

sym cast of each each each string x (i.e.apply the first operation,
sym cast, to the fourth layer of a multi-layer structure)

setting S in k4 is

q)k)S:(nnn;vvv;nvn;nmn;mnv;vnavva)<br><br>S is a general list containing syms and a list of syms<br><br>(),/:S (join empty list to each S) is a trick for making an atom a<br>list while leaving a list unchanged. it converts S to a list of list<br>of sym (no more atomic elements)<br><br>q)k)(),/:S<br>,nnn
,vvv<br>,nvn
,nmn<br>,mnv
vnavva

$S is string of S; it casts each sym item to a string, making S a list
of list of string

q)k)$(),/:S
,“nnn”
,“vvv”
,“nvn”
,“nmn”
,“mnv”
(“vna”;“vva”)

$ is cast to sym; the top layer of the structure is the thing itself;<br>the second layer is the lists of string; the third layer is the<br>individual strings in the lists; the fourth layer is the characters in<br>the strings: $’‘’ applies the cast to the characters

q)k)$'''$(),/:S<br>,nnn
,vvv<br>,nvn
,nmn<br>,mnv
(vna;vva)

Aaron Davies
aaron.davies@gmail.com


> you’ll note the unmatched left brace at the start of theexpressionyes, I see now>$S is string of Sin q not exists monadyc $, therefore I don’t understand, but learn Kdocumentation i understand,Thanks.