0

I have a test.wl file containing say

 l= 5+2

I click on execute button of .wl file, but nothing happens. Some days ago this used to reply 7

I click on update and then call it from a main :

SetDirectory[NotebookDirectory[]];
AppendTo[$Path, Directory[]];
Clear["Global`*"];
Get["test.wl"]
l

but nothing happens. There is no error message, the file is found alright, but not executed.

Now, the documentation of Get says "<<name reads in a file, evaluating each expression in it and returning the last one". This used to be true on my computer some days ago, but not anymore, unless I shift-enter each cell of the .wl.

I can fix the problem by: 1) Quit kernel 2) execute the cells of .wl file by SHIFT-ENTER 3) "Help the .nb file find the .wl file" as below.

SetDirectory[NotebookDirectory[]];
AppendTo[$Path, Directory[]];
FindFile["test`"]
Get[%]
l

So, things do not happen anymore on my new Windows 11 computer, conforming to the DOCUMENTATION (and they seemed to work correctly, in the past). Clearly, the way things work now for me, with coaxing the .nb to find the .wl, shift-enter each cell of the .wl, quitting the kernel when it gets groggy, is not the way scripts are supposed to work. What could be the problem?

florin
  • 1,798
  • 7
  • 12
  • 2
    Try to give the full path in the "Get[ FullPath ]" – Daniel Huber Nov 25 '22 at 11:13
  • 3
    Where is the .wl file with respect to the .nb? p.s. notice that Directory needs []. Also What does FilePrint @ "test.wl" show? my guess is a commented code because Print isn't a Code cell. – Kuba Nov 25 '22 at 11:49
  • 1
    What happens if you do just FindFile["test.wl"]? And what if you do Import["test.wl", "Text"]? – Lukas Lang Nov 27 '22 at 13:15
  • @Kuba FilePrint @ "test.wl" shows (* ::Package:: *)

    (* ::Input:: ) (l=5+2*) But l remains undefined in the .nb file

    – florin Nov 27 '22 at 14:48
  • @LukasLang From the DOCUMENTATION of Import, it does not seem that Import would execute all the cells in the file, without me having to SHIFT-CLICK each of them, and this is precisely what's missing now, since about a week ago. (This is one of the most convenient features of Matlab scripts, and until this mysterious event, I was convinced that .wl files are just like Matlab scripts, modulo needing to click on update button, once changes are done). What could work maybe instead of Import is saving the .wl file at the end as a text file, and then Get["test.txt"]. – florin Nov 27 '22 at 15:16
  • The point of the Import statement was just to see the contents of the file for debugging purposes, not to execute anything. From your FilePrint output, it looks like your cell is not marked as Code/Initilization cell, which is why it is commented out in your .wl. To confirm tgis, can you share a screenshot of the .wl file opened in Mathematica? – Lukas Lang Nov 27 '22 at 16:12
  • How to share a screenshot? I can't find join a file in the menu. But, supposing a cell is not Code/Initilization cell, how do I convert it? – florin Nov 27 '22 at 19:06

0 Answers0