Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Sep 14, 2024
1 parent bf9f5c1 commit 0882e4f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
25 changes: 23 additions & 2 deletions 00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"from pathlib import Path\n",
"from IPython.core.magic import register_cell_magic\n",
"from IPython.display import display, Javascript\n",
"from IPython.paths import get_ipython_dir"
"from IPython.paths import get_ipython_dir\n",
"from shutil import which"
]
},
{
Expand Down Expand Up @@ -324,7 +325,9 @@
"outputs": [],
"source": [
"#|export\n",
"def load_ipython_extension(ipython): create_magic(shell=ipython)"
"def load_ipython_extension(ipython):\n",
" \"Required function for creating magic\"\n",
" create_magic(shell=ipython)"
]
},
{
Expand All @@ -336,6 +339,7 @@
"source": [
"#| export\n",
"def create_ipython_config():\n",
" \"Called by `aplnb_install` to install magic\"\n",
" ipython_dir = Path(get_ipython_dir())\n",
" cf = ipython_dir/'profile_default'/'ipython_config.py'\n",
" cf.parent.mkdir(parents=True, exist_ok=True)\n",
Expand All @@ -344,6 +348,23 @@
" print(f\"Jupyter config updated at {cf}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b352b113",
"metadata": {},
"outputs": [],
"source": [
"def dyalog_cmd():\n",
" \"Helper function to get shell command to run Dyalog\"\n",
" dyalogscript_path = Path(which('dyalogscript.bash'))\n",
" cts = dyalogscript_path.read_text()\n",
" install_dir = re.search(r'^INSTALLDIR=\"([^\"]*)\"', cts, flags=re.MULTILINE).group(1)\n",
" install_dir = \"/Applications/Dyalog-19.0.app/Contents/Resources/dyalog\"\n",
" script_dir = os.environ.get('SCRIPT_DIR', install_dir)\n",
" return f'{script_dir}/dyalog APLKEYS=\"{install_dir}/aplkeys\" APLTRANS=\"{install_dir}/apltrans\"'"
]
},
{
"cell_type": "markdown",
"id": "94ec4289",
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ You can use either a cell magic (`%%ai`) or a line magic (`%ai`). In
either case the expression is evaluated and returned:

``` python
%%apl
y←⍳3
z←y×y
```
Expand All @@ -39,11 +40,13 @@ z←y×y
[1, 4, 9]

``` python
%apl 3×⍳4
```

[3, 6, 9, 12]

``` python
%apl ⎕A
```

'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Expand All @@ -62,12 +65,14 @@ To avoid having the expression returned and/or displayed, end the last
line with a `;`.

``` python
%%apl
a←2 2 ⍴ ⍳4;
```

You can print from cell magics using the standard APL ⎕ glyph:

``` python
%%apl
⎕←a;
```

Expand Down
6 changes: 5 additions & 1 deletion aplnb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from IPython.core.magic import register_cell_magic
from IPython.display import display, Javascript
from IPython.paths import get_ipython_dir
from shutil import which

# %% ../00_core.ipynb
class APLMagic:
Expand Down Expand Up @@ -38,10 +39,13 @@ def create_magic(shell=None):
shell.register_magic_function(apl_magic.apl, 'line_cell', 'apl')

# %% ../00_core.ipynb
def load_ipython_extension(ipython): create_magic(shell=ipython)
def load_ipython_extension(ipython):
"Required function for creating magic"
create_magic(shell=ipython)

# %% ../00_core.ipynb
def create_ipython_config():
"Called by `aplnb_install` to install magic"
ipython_dir = Path(get_ipython_dir())
cf = ipython_dir/'profile_default'/'ipython_config.py'
cf.parent.mkdir(parents=True, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ allowed_cell_metadata_keys =
jupyter_hooks = False
clean_ids = True
clear_all = False

skip_procs = clean_magics

0 comments on commit 0882e4f

Please sign in to comment.