Hi, A year ago I was writing basic Racket programs and I could save image as variable, like this: (define me [img])

Where [img] was an image and I could, of couse, see it in the source code file, or the user could put an save an image in "me" variable when the programs was running.

I tried to make this kindda type, but I couldn't.

how can I do such thing in Nim?

2017-03-18 15:45:35

I don't know the precise how to do it, but you need to open your image file and encode it base64 the entire image file to embed it in your executable.

Or, you can save it in memory during the runtime without any need to encode it to base64.

For rendering the image, look for any lib that specifically does that to your image type.

Racket, or maybe it could be said that Dr.Racket, is whole development IDE. If you're going to code using any text editor, the process would be same.

2017-03-18 16:19:38
@mashingan, could it be a specific Racket IDE text editor feature? Seeing the image of the variable. 2017-03-18 17:30:51
Yes, Android studio has it too to some extent. If you have time spare, maybe you can try to add it to Aporia for that specific feature. I don't have skill to do it
2017-03-18 17:54:37

I think this could be done as an emacs plugin. Emacs already has a mode that allows you to see paths to images as the image themself in the editor. iimage.el is the *mode* (emacs term) that controls the behavior of it. If you understand it, I think you can create a mode on your own that does exactly what you want. Or you find a way how this general solution applies to help your problem.

2017-03-20 12:10:36

This will not show an image but you can embed binary data at compile time with something like this

import os, macros, base64

macro embed_binary_file(var_name:untyped,filename:string) : typed =
  let bin64 = base64.encode(slurp(filename.strVal))
  result = newStmtList()
  result.add(newLetStmt(var_name,newStrLitNode(bin64)))

embed_binary_file(img,"digits.bmp")
echo("Image Data:" & $img)

2017-03-20 15:15:28
You should know, that when you want to be able to see a variable as an image in the editor, it is more an editor feature, than a language feature. You would have to implement that in the editor of your choice on your own. But even then it is not trivial, because you would also have some support from nimsuggest, that is currently not there. When you are really convincey that this feature is a necessity, I guess you could implement it at least to some extent, but when you think it would be a few lines of code here and there you are better off by accepting that this is not a feature of Nim. 2017-03-20 15:51:17