type conversions/Conversion Codes

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Re: type conversions/Conversion Codes

Postby Stu on Mon Jan 11, 2016 3:56 pm

Hi Vince,

OO is second nature to you young guys. It was invented when I was already at mid-career and has always seemed like overkill for the small projects I actually do. I am studying the Object Reference however. There is SO much good stuff in there!

-Stu
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: type conversions/Conversion Codes

Postby Morten|Dyalog on Mon Jan 11, 2016 8:25 pm

Stu wrote:OO is second nature to you young guys. It was invented when I was already at mid-career...


Actually, OO was invented at more or less the same time as APL: https://en.wikipedia.org/wiki/Simula. And although some would say it took a while to become popular, one could also argue that it caught on a bit quicker than APL - we're still working on that ;-)

I agree OO is overkill for many projects, but in my experience it is a pretty good tool of thought or interfaces between different components.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: type conversions/Conversion Codes

Postby Stu on Sun Jan 31, 2016 1:29 am

I use the following function to write a bitmap to a .bmp file:

bits writebmp file
'bm'⎕WC'bitmap'('Bits'bits)('Cmap'(2 3⍴0 0 0 255 255 255))
bm.File←mypath,file
2 ⎕NQ'bm' 'FileWrite'

If I try to read the file back in with the following function, I get either a VALUE ERROR or a DOMAIN ERROR, depending on whether or not I use parentheses:

argb←mypath readbmp file
bmp←⎕WC 'bitmap' (mypath,file,'.bmp')
bits←bmp.Cbits
⎕EX 'bmp'
argb←256 256 256⊤bits

file='test'
mypath='C:\Users\Stuart Smith\Desktop\'

I'm obviously doing something wrong, but I can't see it.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: type conversions/Conversion Codes

Postby Veli-Matti on Sun Jan 31, 2016 2:17 pm

Hi,
a little bit editing is needed:

      argb←mypath readbmp file;bmp
'bmp'⎕WC'Bitmap'(mypath,file,'.bmp')
argb←256 256 256⊤bmp.CBits

i.e. the object name was missing (assign does not work here the way you expected) and the property name was mistyped (they are case-sensitive)

Yours
- Veli-Matti
Veli-Matti
 
Posts: 93
Joined: Sat Nov 28, 2009 3:12 pm

Re: type conversions/Conversion Codes

Postby Stu on Sun Jan 31, 2016 4:09 pm

Aha! It all works now. Thanks!
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: type conversions/Conversion Codes

Postby Stu on Mon Feb 01, 2016 3:07 pm

I've been using the following function to write bitmaps to .bmp files:

bits writebmp file
'bm'⎕WC'bitmap'('Bits'bits)('Cmap'(2 3⍴255 255 255 0 0 0))
bm.File←mypath,file
2 ⎕NQ'bm' 'FileWrite'

It works fine, but now every time I launch APL, I get a message to the effect that the object #.bm cannot be rebuilt. This does not prevent me from using the workspace, but it's clear I should be doing something so that I don't get that message. What is it that I should be doing?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: type conversions/Conversion Codes

Postby AndyS|Dyalog on Tue Feb 02, 2016 9:44 am

You could set bm.KeepBits to 1, so that the bits are saved in the workspace. But better may be to simply localise bm in your function, so that nothing of the Bitmap bm is retained in the saved workspace provided that you don't save the workspace with writemp in a suspended state ..
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm

Re: type conversions/Conversion Codes

Postby Vince|Dyalog on Tue Feb 02, 2016 9:54 am

Hi Stu,

You're getting this message as Dyalog is trying to recreate the bitmap from the file specified in the File property, but the file no longer exists.

If you set KeepBits on bm to 1, we will keep the image information of the bitmap in the workspace and you won't have to create it each time.
      'bm'⎕WC'bitmap'('Bits'bits)('Cmap'(2 3⍴255 255 255 0 0 0))('keepbits' 1)

Alternatively, before you save the workspace, you can ⎕ex '#.bm'
This erases the bm object.

If you don't need to keep bm and intend it to be purely temporary, you can localize it at the top of writebmp and it will be erased when writebmp finishes.

e.g.
      ∇ bits writebmp file;bm                                                                                                                                 
[1] 'bm'⎕WC'bitmap'('Bits'bits)('Cmap'(2 3⍴255 255 255 0 0 0))
[2] bm.File←mypath,file
[3] 2 ⎕NQ'bm' 'FileWrite'


Regards,

Vince
Vince|Dyalog
 
Posts: 412
Joined: Wed Oct 01, 2008 9:39 am

Re: type conversions/Conversion Codes

Postby Stu on Tue Feb 02, 2016 4:01 pm

Duh! Why didn't I think of that?

Thanks!

Is there a place where you can learn about OO in Dyalog? "Mastering APL" seems not to mention it, and the "Object Reference" assumes you already know all about OO programming. I used "old" APL in the late 1970's, before OO had been added to the language. My instinct is to write code in that obsolete style.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: type conversions/Conversion Codes

Postby JoHo on Tue Feb 02, 2016 5:33 pm

In your Dyalog installation under the Help Menu / Documentation Center / there should be

Tutorials
Object Oriented Programming for APL Programmers
Object Oriented Programming for Impatient APL Programmers
DYALOG.NET Unicode Tutorial (requires IIS)
- - -

online I found:
http://help.dyalog.com/14.1/
under Programmer's Guide - Object Oriented Programming

HTH
/JoHo

PS:
I think, that in general the classic APL style is still very useful in many application cases. I think of OO as a method of organizing or packaging APL code in a compatible way to the rest of the world.
User avatar
JoHo
 
Posts: 37
Joined: Sat Nov 28, 2009 12:51 pm
Location: Austria, EU

PreviousNext

Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest