Menu

Working with Packages

2019-08-26
2019-08-26
  • Yves Cloutier

    Yves Cloutier - 2019-08-26

    Hello,

    Would it be possible to share abit more on how to properly create and use packages?

    For example I have created a file String.icn with package definition:

    package String
    procedure split(s)
      return if marker := find(" ", s) then {
        [s[1:marker]] ||| split(s[marker+1:0])
      }
      else {
        [s]
      }
    end 
    

    What are the steps to import this into a program? I have compiled it first, then compiled my main program which has:

    import String

    However I get an error that the package doesnt exist.

    Any tips would be great.

    Regards

     
  • Jafar

    Jafar - 2019-08-26

    I'm assuming your main program and the package are in the same directory, correct? if that is the case then it should work by default without having to set IPATH and LAPTH. if it doesn't then we ay have a bug. Set your Unicon's environment variables IPATH and LPATH to include the current directory and try to compoile your main program again.

     
  • Yves Cloutier

    Yves Cloutier - 2019-08-26

    Jafar, yes correct, all my files are in the same directory.

    First I did:

    unicon String.icn

    followed by:

    packagetest.icn

    and get the following:

    D:\Dev\Unicon>unicon String.icn
    Parsing String.icn: String.icn is already in Package string
    ..split is already in Package string
    
    d:\apps\Unicon\bin\icont.exe -c   -O String.icn C:\Users\NV7547\AppData\Local\Temp\uni13967197
    Translating:
    String.icn:
      string__split
    No errors
    d:\apps\Unicon\bin\icont.exe  String.u
    Linking:
    
    D:\Dev\Unicon>unicon packagetest.icn
    Parsing strings.icn: ...
    d:\apps\Unicon\bin\icont.exe -c   -O packagetest.icn C:\Users\NV7547\AppData\Local\Temp\uni18337549
    Translating:
    packagetest.icn:
      sum
      main
    No errors
    d:\apps\Unicon\bin\icont.exe  packagetest.u
    Linking:
    icont: cannot resolve reference to file 'D:/Dev/Unicon/String.u'
    

    I am usually on Linux. But for the while being Im on Windows 10. Its been a while since using Windows...Could you jog my memory on how to set path vars in Windows?

     
  • Jafar

    Jafar - 2019-08-26

    I will give that a test when I get a chance.

    to set the two variable on windows do

    set IPATH=.
    set LPATH=.

    and then continue your commands

     
  • Jafar

    Jafar - 2019-08-26

    Yves,
    Just noticed! you compiled your package file with

       unicon String.icn
    

    and not

       unicon -c String.icn
    

    The first command without the -c will produce an executable, not a link-able module/package. That is why you get :

       icont: cannot resolve reference to file 'D:/Dev/Unicon/String.u'
    

    The file isn't there! :)

     

    Last edit: Jafar 2019-08-26
  • Yves Cloutier

    Yves Cloutier - 2019-08-26

    Jafar, uncon -c did the trick! That was the issue.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.