bill lam wrote:
> This is impressive but this is only possible because dyalog is bundled
> with com/.net. I think this is the same reason why dyalog can attract
> young programmers, or do they want to work with emacs ?
>
> I suppose your com/.net example also requires an excel license to work.
Well, "bundled" is a strong word - we don't require any of these things to be
present - but of course you cannot drive Excel unless it is on your machine.
The hard work is in the language, not in the individual bridges to (logically
more or less equivalent) object frameworks. We could relatively extend this to
Java, Ruby objects - and Mono (Open Source .NET for Unixes) when there is
sufficient demand (or the marketing dept gets enough clout to demand it).
Also note that the syntax applies to our "namespaces" and instances of objects
that you create in APL - it doesn't require "external" objects at all. So you
can have an vector of record "instances" called "database" and write
expressions like:
((Database.Sales>100)/Database).(Discount+←0.1)
... which is also cool stuff ... Arrays of objects (containing arrays of ...)
can be quite pleasant to work with.
At the moment, you can use external COM objects on Windows or WINE-based
systems, or DotNet. Very many Windows apps support some form of "automation -
under Windows, it is very common for applications to do this - so this applies
not only to Excel but also Word and the rest of the MS Office suite - probably
also OpenOffice, and most other applications in one form or another).
On my Windows laptop:
⍴'.' ⎕WG 'OLEServers' ⍝ Count the number of registered COM/OLE Servers
5803
Where .NET is available, you have more "utility functions" than you saw in your
life. And the beauty is that they are all "self-describing" (you can read about
them using Google and then query the interface from APL), and unlike
traditional API functions they give you a DOMAIN ERROR if you call them
incorrectly, rather than just crashing your interpreter or the whole operating
system...
Imagine the file 'c:\docs\sjt\folder.xml' is an XML document that begins like
this:
--------
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <folder>
<title lang="en">Underwater</title>
<title lang="jp">水のなか</title>
<description lang="en">Jellyfish in Japanese aquaria</description>
<description lang="jp">日本の水族館で見たクラゲたち</description>
<keywords lang="en">water, jellyfish, red, flat, aquarium, blue,
tentacle</keywords>
<keywords lang="jp">水, クラゲ, 赤, 浮遊, 水族館, 青, 触手, 海遊館, ジェリー, ブルー</keywords>
- <thumbs>
<row>1 2 3 4</row>
<row>5 6</row>
<row>7 8</row>
<row>9 10 11 12</row>
</thumbs>
- <!-- you can write comments like this
-->
- <image id="1" file="escalator.jpg">
<title lang="en">Blue jelly</title>
<title lang="jp">ブルージェリー</title>
<description lang="en" show="never">Catostylus mosaicus, Blue
blubber</description>
</image>
...
---etc---
⎕USING←'System.Xml,System.Xml.dll'⍝ Declare intent to use .NET assembly
(doc←⎕NEW XmlDocument).Load⊂'c:\docs\sjt\folder.xml' ⍝ Create
"XmlDocument" object and call Load
⍴els←⌷doc.LastChild.ChildNodes ⍝ monadic ⌷ materializes external
collection as an array
21
3↑els
System.Xml.XmlElement System.Xml.XmlElement System.Xml.XmlElement
els[0].⎕nl -2 ⍝ query properties exposed by first element
Attributes BaseURI ChildNodes FirstChild HasAttributes HasChildNodes
InnerText InnerXml IsEmpty IsReadOnly Item LastChild LocalName Name
NamespaceURI NextSibling NodeType OuterXml OwnerDocument ParentNode
Prefix PreviousSibling SchemaInfo Value
els[0].(LocalName InnerText) ⍝ 2 properties from first node
title Underwater
↑els[⍳4].(LocalName InnerText, Attributes[0].Value) ⍝ mix data from 4
nodes, including first attribute value
title Underwater en
title 水のなか jp
description Jellyfish in Japanese aquaria en
description 日本の水族館で見たクラゲた jp
els[0].(⌷Attributes).(Name Value) ⍝ Name and Value for all Attributes of
first element
lang en
els.(⌷Attributes).(Name Value) ⍝ Ditto for ALL elements
VALUE ERROR
els.(⌷Attributes).(Name Value) ⍝ Oops - at least one node did not have
any attributes
∧
3↑els.{0::⍬ ⋄ (⌷Attributes).(Name Value)}0 ⍝ dfn with error guard applied
to each element
lang en lang jp lang en
Morten
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm