Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - cameyo

#181
newLISP in the real world / Understand "curry" function
November 25, 2018, 01:28:10 AM
This is what I understand ...



I can map a function with multiple arguments in this way:
(map pow '(2 1) '(3 4))
;-> (8 1)

where: 8 = 2^3, 1 = 1^4

But, if the list of arguments are within a list:
(setq lst '((2 1) (3 4)))
I got an error:
(map pow lst)
ERR: value expected in function pow : '(2 1)

I use "curry" to solve this problem:
(map (curry apply pow) lst)
;-> (2 81)

where: 2 = 2^1, 81 = 3^4

Ok, transpose the list of arguments:
(map (curry apply pow) (transpose lst))
;-> (8 1)

This is equivalent to:
(map (lambda(x) (apply pow x)) (transpose lst))
;-> (8 1)

We can define a user function too:
(define (mypow lst)
  (if (null? lst) '()
      (cons (pow (nth '(0 0) lst) (nth '(0 1) lst)) (mypow (rest lst)))
  )
)

(setq lst '((2 1) (3 4)))
(mypow (transpose lst))
;-> (8 1)

Another example:
(map max '(3 5) '(2 7))
;-> (3 7)
(map (curry apply max) '((3 5) (2 7)))
;-> (5 7)
(map (curry apply max) (transpose '((3 5) (2 7))))
;-> (3 7)


Did I get it right?

cameyo

p.s. sorry for poor english...
#182
The book "A Practical Introduction to Fuzzy Logic using LISP" contains a section that explains the management of csv files (builds a simple CSV library).

The code is written in newLisp.



cameyo
#183
newLISP in the real world / Notepad++ bundle
November 21, 2018, 08:09:00 AM
Download: https://github.com/cameyo42/notepadpp-newlisp">//https://github.com/cameyo42/notepadpp-newlisp



Add newlisp syntax highlighting

Copy all the text of the file: newlisp-udl.xml

and paste it inside the section:<NotepadPlus> ... </NotepadPlus>

of the file: userDefineLang.xml (located at: c:Users<username>AppDataRoamingNotepad++)
Example
<NotepadPlus>
    <UserLang name="newLISP" ext="lsp" udlVersion="2.1">
    ...
    </UserLang>
</NotepadPlus>
   

The newlisp keywords are from primes.h (newlisp source).

The actual highlight colors are for "obsidiane" theme of notepad++.

You can change (easily) the colors as you like.



Open newlisp help from notepad++

Add the line: <Command name="newLISP Help" Ctrl="yes" Alt="yes" Shift="no" Key="112">chrome file:///C:/Program%20Files%20(x86)/newlisp/newlisp_manual.html#$(CURRENT_WORD)</Command>
inside the section: <UserDefinedCommands> ... </UserDefinedCommands>

of the file: shortcut.xml (located at: c:Users<username>AppDataRoamingNotepad++)
Example
<UserDefinedCommands>
    <Command name="newLISP Help" Ctrl="yes" Alt="yes" Shift="no" Key="112">chrome file:///C:/Program%20Files%20(x86)/newlisp/newlisp_manual.html#$(CURRENT_WORD)</Command>
   
</UserDefinedCommands>

Note: change the path to point to your newlisp help file

Now you can select a word and press Ctrl+Alt+F1 to open newlisp help file.

The shortcut is Ctrl+Alt+F1, but you can change it.



Execute newlisp code from notepad++

Download and install autohotkey (http://www.autohotkey.com">http://www.autohotkey.com).

Run the script npp-newlisp.ahk (double click it).

Run notepad++

Press Win+F12 to start newlisp REPL

Now, from notepad++, you can:

1) Execute the expression of current line pressing: Left-Shift + Enter

2) Execute a selected block of expression pressing: Right-Shift + Enter

After the execution of the expressions, notepad++ is the active application.

Note:

When selecting a block of expression be sure to begin and end the selection

with a blank line (or use [cmd] [/cmd]).

Note:

The script npp-newlisp.ahk exchange the brackets () and [] in the keyboard.

You can edit the file to disable this (you must comment two lines).

The script also enable other shortcuts... see the source.

Happy coding



cameyo
#184
newLISP in the real world / Re: Apply error message
November 18, 2018, 02:58:03 AM
Thanks.

A big help for me.



cameyo
#185
newLISP in the real world / Re: Apply error message
November 17, 2018, 12:05:49 PM
"transpose" works like i want :-)

But is the expression wrong logically or syntactically?

Why  "apply" does not receive a list?

Thanks again



cameyo
#186
newLISP in the real world / Apply error message
November 17, 2018, 07:03:06 AM
The following expression give me an error:
(apply map list '((a 1) (b 2) (c 3)))
QuoteERR: list expected in function apply : list@4095B0

Instead, I wish the output was:
Quote((a b c) (1 2 3))

Can someone help me?

Thanks



cameyo
#187
newLISP in the real world / Re: FUNCALL and GETDEF
October 26, 2018, 11:58:55 PM
Hi newbert,

I have found these functions in an old article on Lisp (to define a function it use DE, maybe Portable Standard Lisp).

GETDEF gets the definition of a function.

Thanks for infos.
#188
newLISP in the real world / FUNCALL and GETDEF
October 26, 2018, 12:29:24 AM
Hi all,

i'm looking for the functions FUNCALL and GETDEF.

Are there equivalent functions in newLisp?

Sorry for dumb question...i'm a newbie.

cameyo
#189

;=====================================
; edit2newlisp.ahk
; Connect newLisp and editor
; AutoHotkey:     1.x
; Language:       English
; Platform:       Windows7
; Author:         cameyo - 2017
; License:        MIT license
;=====================================
; Hotkeys:
; Win-F12 -> Start newLisp
; Left_Shift-Enter -> Evaluate current line
; Right_Shift-Enter -> Evaluate selected block

;=====================================
; How to set your editor:
; 1: run winspy utility (bundled with autohotkey)
; 2: run your editor
; 3: copy the ahk_class text value
; 4: set the global variable editor to "<ahk_class>"
; 5: That's all.
; EXAMPLES:
; (notepad++):
;global editor = "notepad++"
; (SciTE):
;global editor = "SciTEWindow"
; (Notepad)
;global editor = "Notepad";
; (PSPad)
;global editor = "TfPSPad.UnicodeClass"
; (Programmer's Notepad)
;global editor = "ATL:006AD5B8"
; (Sublime Text)
;global editor = "PX_WINDOW_CLASS"
;-------------------------------------
global editor = "notepad++"
;-------------------------------------
; To use (and view) the greek letters the editor must be set to UTF-8 encoding.
;=====================================

;=====================================
; Basic hotkeys symbol
;=====================================
; # Win key
; ! Alt key
; ^ Control key
; + Shift key

;=====================================
; General statements
;=====================================
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force ; Allow reload script
#WinActivateForce ; activate window with forceful method

;=====================================
; Global variables
;=====================================
#EscapeChar
global hasRunnewLisp = 0
global newLispPID = 0
global editorPID = 0

;---------------------------
OpennewLisp()
{
  if %hasRunnewLisp% = 0
  {
    Run newlisp.exe,,,newLispPID
    hasRunnewLisp = 1
    ReturnToEditor()
    return
  }
  Process, Exist, %newLispPID%
  if %ErrorLevel% = 0
  {
    Run newlisp.exe,,,newLispPID
    hasRunnewLisp = 1
    ReturnToEditor()
    return
  }
}
;---------------------------
ReOpennewLisp()
{
  WinClose, ahk_pid %newLispPID%
  OpennewLisp()
}
;---------------------------
SendTonewLisp()
{
  OpennewLisp()
  WinWait, ahk_pid %newLispPID%
  WinActivate, ahk_pid %newLispPID%
  WinWaitActive, ahk_pid %newLispPID%

  ; Past via menu (must disable SendMode Input)
  ;Send {Alt Down}{Space}{Alt up}ep{Enter}

  ; Past with send clipboard
  StringReplace clipboard2, clipboard, rn, n, All
  SendInput {Raw}%clipboard2%n
}
;---------------------------
ReturnToEditor()
{
  WinActivate, ahk_pid %editorPID%
  SendInput {End}
}
;---------------------------
PassLine()
{
  WinGetCLASS, currentClass, A
  If currentClass = %editor%
  {
    WinGet, editorPID, PID, A
    SendInput {Home}{Shift Down}{End}{Shift Up}{Ctrl Down}c{Ctrl Up}{End}
    SendTonewLisp()
    ReturnToEditor()
  }
}
;---------------------------
PassBlock()
{
  WinGetCLASS, currentClass, A
  If currentClass = %editor%
  {
    WinGet, editorPID, PID, A
    SendInput {Ctrl Down}c{Ctrl Up}
    SendTonewLisp()
    ReturnToEditor()
  }
}
;---------------------------
; Eval current line (Left Shift - Enter)
LShift & Enter:: PassLine()
;---------------------------
; Eval selected block (Right Shift - Enter)
RShift & Enter:: PassBlock()
;---------------------------
; Run newLisp (Win-F12)
#$F12:: ReOpennewLisp()

;================================================
; REPL enhancements
; Work only on console window
#IfWinActive ahk_class ConsoleWindowClass

;=============================
; Scroll command window back and forward
; Ctrl+PageUp / PageDown
;=============================
^PgUp:: SendInput {WheelUp}

^PgDn:: SendInput {WheelDown}

;=============================
; Paste in REPL
; Ctrl-V
; Better version
;=============================
^V::
StringReplace clipboard2, clipboard, rn, n, All
SendInput {Raw}%clipboard2%
return

;=============================
; Paste in REPL
; Ctrl-V
; Old version (must disable SendMode Input)
;=============================
;^V::
; English menu (Edit->Paste)
;Send !{Space}ep
;return

#IfWinActive
;================================================

;=============================
; Greek Letters (lowercase)
; Control-Win-<char>
; char 'j' can't be used (REPL)
; char 'q' is free...
; To use (and view) the greek letters the editor must be set to UTF-8 encoding.
;=============================
^#a:: SendInput {U+03B1} ; alpha
^#b:: SendInput {U+03B2} ; beta
^#g:: SendInput {U+03B3} ; gamma
^#d:: SendInput {U+03B4} ; delta
^#y:: SendInput {U+03B5} ; epsilon (y)
^#z:: SendInput {U+03B6} ; zeta
^#e:: SendInput {U+03B7} ; eta
^#h:: SendInput {U+03B8} ; theta (h)
^#i:: SendInput {U+03B9} ; iota
^#k:: SendInput {U+03BA} ; kappa
^#l:: SendInput {U+03BB} ; lambda
^#m:: SendInput {U+03BC} ; mu
^#n:: SendInput {U+03BD} ; nu
^#x:: SendInput {U+03BE} ; xi
^#o:: SendInput {U+03BF} ; omicron
^#p:: SendInput {U+03C0} ; pi
^#r:: SendInput {U+03C1} ; rho
^#s:: SendInput {U+03C3} ; sigma
^#t:: SendInput {U+03C4} ; tau
^#u:: SendInput {U+03C5} ; upsilon
^#f:: SendInput {U+03C6} ; phi (f)
^#c:: SendInput {U+03C7} ; chi
^#v:: SendInput {U+03C8} ; psi (v)
^#w:: SendInput {U+03C9} ; omega (w)
#190
I'm reading it too. I have converted the first game (guess-game)...

It is an interesting method to learn more about Common Lisp and Newlisp.

Have a nice day.



cameyo
#191
Has anyone got a newLISP syntax file for notepad++?



Thanks