Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- q-bies
- :
- Have I developed the functional equivalent of a Bo...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2022.03.17 11:21 AM

1 ACCEPTED SOLUTION

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2022.03.18 01:16 AM

You’re infested with parens! They might be confusing you.

First, those multiple right parens in the prompts: that’s not q trying to look like Python. Each right paren after the initial `q)`

indicates a suspended evaluation with associated state. Unless you’re exploring that state, best to cut back the stack with a backslash lest you find names resolving in suspended state. (No sign of that here, but it’s good practice.)

```
q){(x*y)-1 y*x}[0;0]
'type
[1] {(x*y)-1 y*x}
^
q)) x / suspended state
0
q))\
q)x / suspension cleared, no value of x
'x
[0] x / suspension cleared, no value of x
^
```

Second, redundant – and missing – parens in your lambda indicate the syntax is new to you. The most important syntactic rule is that there is *no hierarchy of functions*. Operators are binary functions with infix syntax. They have short left scope and long right scope. The left argument is the value immediately on the left. The right argument of an operator, or the argument of a unary function, is the result of evaluating *everything to its right*. Famously:

```
q)3*4+5
27
```

Syntactically, a republic of functions. No precedence rules to remember. Just the above. (One rule to rule them all…)

IO handles are integers. When you `hopen`

a file or IO stream the handle for it is an integer and the integer behaves like a function. You can apply it. When you apply a file handle to an argument, the argument gets written to the file. The integers 0, 1, and 2 permanently refer respectively to the console, stdout, and stderr.

So `(x*y)-1 ((y)*x)`

tries to write `y*x`

to stdout. (Oops, type error, needs to be text.)

Understanding this, we can rewrite your tests:

```
q){(x*y)-y*x}[0;0]
0
q){(x*y)-y*x}[0;1]
0
q){(x*y)-y*x}[1;1]
0
```

None of which will surprise you.

To continue your exploration you might like to use Each Right Each Left `/:\:`

with a lambda to tabulate results:

```
q)10 20 30 +/:\:1 2 3 4 5
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
q)0 1{(x*y)-y*x}/:\:0 1
0 0
0 0
```

1 REPLY 1

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

2022.03.18 01:16 AM

You’re infested with parens! They might be confusing you.

First, those multiple right parens in the prompts: that’s not q trying to look like Python. Each right paren after the initial `q)`

indicates a suspended evaluation with associated state. Unless you’re exploring that state, best to cut back the stack with a backslash lest you find names resolving in suspended state. (No sign of that here, but it’s good practice.)

```
q){(x*y)-1 y*x}[0;0]
'type
[1] {(x*y)-1 y*x}
^
q)) x / suspended state
0
q))\
q)x / suspension cleared, no value of x
'x
[0] x / suspension cleared, no value of x
^
```

Second, redundant – and missing – parens in your lambda indicate the syntax is new to you. The most important syntactic rule is that there is *no hierarchy of functions*. Operators are binary functions with infix syntax. They have short left scope and long right scope. The left argument is the value immediately on the left. The right argument of an operator, or the argument of a unary function, is the result of evaluating *everything to its right*. Famously:

```
q)3*4+5
27
```

Syntactically, a republic of functions. No precedence rules to remember. Just the above. (One rule to rule them all…)

IO handles are integers. When you `hopen`

a file or IO stream the handle for it is an integer and the integer behaves like a function. You can apply it. When you apply a file handle to an argument, the argument gets written to the file. The integers 0, 1, and 2 permanently refer respectively to the console, stdout, and stderr.

So `(x*y)-1 ((y)*x)`

tries to write `y*x`

to stdout. (Oops, type error, needs to be text.)

Understanding this, we can rewrite your tests:

```
q){(x*y)-y*x}[0;0]
0
q){(x*y)-y*x}[0;1]
0
q){(x*y)-y*x}[1;1]
0
```

None of which will surprise you.

To continue your exploration you might like to use Each Right Each Left `/:\:`

with a lambda to tabulate results:

```
q)10 20 30 +/:\:1 2 3 4 5
11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
q)0 1{(x*y)-y*x}/:\:0 1
0 0
0 0
```

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Resources

Popular Links

Follow Us

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.