unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Lisp Live buffer
@ 2022-12-06 15:44 Emanuel Berg
  2022-12-07  3:06 ` Jean Louis
  2022-12-08 11:32 ` Madhu
  0 siblings, 2 replies; 14+ messages in thread
From: Emanuel Berg @ 2022-12-06 15:44 UTC (permalink / raw)
  To: help-gnu-emacs

I'd like a buffer that shows Lisp Live ...

you say it should show some list or data structure, it
visualizes it (can/should be text only) and then if I in some
other buffer or wherever basically append to the list or
whatever it's updated in the live buffer - like watch(1),
maybe, only cooler ...

That way, one could make a whole game text only and then throw
it at some GFX guys, hey, draw this, and have 100% MVC
separation (and "in parallel", throw it to some other guys and
get two games that are actually the same, but not ...)

IOW: GaaS! (Game as a Service/Server :))

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-06 15:44 Lisp Live buffer Emanuel Berg
@ 2022-12-07  3:06 ` Jean Louis
  2022-12-07  3:54   ` Emanuel Berg
  2022-12-08 11:32 ` Madhu
  1 sibling, 1 reply; 14+ messages in thread
From: Jean Louis @ 2022-12-07  3:06 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

Just use prin1-to-string and insert updated structure in intervals.

Jean



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-07  3:06 ` Jean Louis
@ 2022-12-07  3:54   ` Emanuel Berg
  2022-12-23  8:15     ` Jean Louis
  0 siblings, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2022-12-07  3:54 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Just use prin1-to-string and insert updated structure
> in intervals.

For example this WarGames Spanish football game?

(setq ttt-board
  (list
    '(x o o)
    '(· x ·)
    '(· · x) ))

Next cool thing would be there would not be any 'score' or
other stats stored in variables, instead that would be
computed from the board (game world) each time ...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-06 15:44 Lisp Live buffer Emanuel Berg
  2022-12-07  3:06 ` Jean Louis
@ 2022-12-08 11:32 ` Madhu
  2022-12-23  8:23   ` Jean Louis
  1 sibling, 1 reply; 14+ messages in thread
From: Madhu @ 2022-12-08 11:32 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <87sfhsczaa.fsf @dataswamp.org> :
Wrote on Tue, 06 Dec 2022 16:44:29 +0100:

> I'd like a buffer that shows Lisp Live ...
>
> you say it should show some list or data structure, it
> visualizes it (can/should be text only) and then if I in some
> other buffer or wherever basically append to the list or
> whatever it's updated in the live buffer - like watch(1),
> maybe, only cooler ...
>
> That way, one could make a whole game text only and then throw
> it at some GFX guys, hey, draw this, and have 100% MVC
> separation (and "in parallel", throw it to some other guys and
> get two games that are actually the same, but not ...)
>
> IOW: GaaS! (Game as a Service/Server :))

you've seen lively.el https://lukego.livejournal.com/23379.html
?




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-07  3:54   ` Emanuel Berg
@ 2022-12-23  8:15     ` Jean Louis
  2022-12-26 20:26       ` Emanuel Berg
  0 siblings, 1 reply; 14+ messages in thread
From: Jean Louis @ 2022-12-23  8:15 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-12-07 15:09]:
> Jean Louis wrote:
> 
> > Just use prin1-to-string and insert updated structure
> > in intervals.
> 
> For example this WarGames Spanish football game?
> 
> (setq ttt-board
>   (list
>     '(x o o)
>     '(· x ·)
>     '(· · x) ))
> 
> Next cool thing would be there would not be any 'score' or
> other stats stored in variables, instead that would be
> computed from the board (game world) each time ...

When you mention it, I must think that there must be some variable
telling who was the last player, as for game to determine who wins it.

Deviation from subject:

I can only guess that such game exist in Emacs. Though I could use my
package rcd-box.el to construct the interface.

(rcd-box-table '(("X" " " "X")
		 (" " "X" "O")
		 (" " " " "O"))) ➜ "
╔═══╦═══╦═══╗
║ X ║   ║ X ║
╠═══╬═══╬═══╣
║   ║ X ║ O ║
╠═══╬═══╬═══╣
║   ║   ║ O ║
╚═══╩═══╩═══╝

"

And I know I can insert buttons as well, by using RCD Utilities
function `rcd-button-insert', see footnote.

(insert 
 (rcd-box-table (list (list "X" " " (with-temp-buffer (rcd-button-insert "X" 'ignore) (buffer-string)))
		      '(" " "X" "O")
		      '(" " " " "O"))))
╔═══╦═══╦═══╗
║ X ║   ║ X ║ <--- this X becomes visible as button
╠═══╬═══╬═══╣
║   ║ X ║ O ║
╠═══╬═══╬═══╣
║   ║   ║ O ║
╚═══╩═══╩═══╝

Buttons may have it's functions, so clicking on the button could
remove or eventually place something in the list, and redraw the
table.

Somebody called Gomoku Tic Tac Toe, but it is not same, though similar.

Emacs Tic Tac Toe. It is called gomoku in Emacs. Use the… | by Akash Manohar | 1 command a day | Medium:
https://medium.com/1cmd/emacs-tic-tac-toe-81a334fd3fd7

Version exists here, but the author hosted images at imgur.com which are not available any more:

accidentalrebel/emacs-tic-tac-toe-improved: An improved tic-tac-toe game project for me to practice my Emacs Lisp.:
https://github.com/accidentalrebel/emacs-tic-tac-toe-improved

Other version is here:
https://github.com/accidentalrebel/emacs-tic-tac-toe-game/blob/master/tic-tac.el

That is such a boring game, and also unfair, as once trick is known, there will be too many wins.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/

GNU Emacs package: rcd-utilities.el :
https://gnu.support/gnu-emacs/packages/rcd-utilities-el.html



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-08 11:32 ` Madhu
@ 2022-12-23  8:23   ` Jean Louis
  0 siblings, 0 replies; 14+ messages in thread
From: Jean Louis @ 2022-12-23  8:23 UTC (permalink / raw)
  To: Madhu; +Cc: help-gnu-emacs

* Madhu <enometh@meer.net> [2022-12-08 14:34]:
> * Emanuel Berg <87sfhsczaa.fsf @dataswamp.org> :
> Wrote on Tue, 06 Dec 2022 16:44:29 +0100:
> 
> > I'd like a buffer that shows Lisp Live ...
> >
> > you say it should show some list or data structure, it
> > visualizes it (can/should be text only) and then if I in some
> > other buffer or wherever basically append to the list or
> > whatever it's updated in the live buffer - like watch(1),
> > maybe, only cooler ...

OK the lively functions or similar principle solve the above intention.

> > That way, one could make a whole game text only and then throw
> > it at some GFX guys, hey, draw this, and have 100% MVC
> > separation (and "in parallel", throw it to some other guys and
> > get two games that are actually the same, but not ...)

Doesn't that already exist in EIEIO?

EIEIO (“Enhanced Implementation of Emacs Interpreted Objects”)
provides an Object Oriented layer for Emacs Lisp, following the basic
concepts of the Common Lisp Object System (CLOS). It provides a
framework for writing object-oriented applications in Emacs.

> you've seen lively.el https://lukego.livejournal.com/23379.html

;;; Go to the end of any of the following lines and run `M-x lively'
;;;   Current time:      Fri Dec 23 11:19:41 2022
;;;   Last command:      last-command
;;;   Open buffers:      208
;;;   Unix processes:    (lively-shell-command "ps -a | wc -l")

Those functions are very useful, thanks. I keep for later as sometimes
I do need it, for example when we run campaign and new people leads
are continually and hourly entered into the database. 

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-23  8:15     ` Jean Louis
@ 2022-12-26 20:26       ` Emanuel Berg
  2022-12-27  1:12         ` Emanuel Berg
  0 siblings, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2022-12-26 20:26 UTC (permalink / raw)
  To: help-gnu-emacs

> (setq ttt-board
>   (list
>     '(x o o)
>     '(· x ·)
>     '(· · x) ))

I have tried to do a MVC Elisp demo but the function 'world-set' is
incorrect, I still didn't get past that step. See below, it's line
32-38. The result is visible in the test function and it's
output, last.

What is needed is essentially a multidimensional array and then
getters and setters (based on indexes or coordinates) to operate
on that.

Ideas?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/mvc/model.el

(require 'cl-lib)

(defun make-world (dim len &optional init)
  (or init (setq init "."))
  (if (= dim 1)
      (make-list len init)
    (make-list len (make-world (1- dim) len init)) ))

(defun world-size (world)
  (length (flatten-list world)) )

(defun make-world-test ()
  (let ((tests (list (list "cell"  (make-world 1 1)  1)
                     (list "ttt"   (make-world 2 3)  9)
                     (list "chess" (make-world 2 8) 64)
                     (list "cube"  (make-world 3 3) 27) )))
    (cl-loop
      for (name world expected) in tests
      and num-tests from 0 do
        (let ((size (world-size world)))
          (unless (= size expected)
            (error "World %s has size %s, expected %s" name size expected) ))
      finally return (= num-tests (length tests)) )))

;; (make-world-test)

(defun world-set (world pos to)
  (if (= 1 (length pos))
      (setcar (nthcdr (car pos) world) to)
    (setcar
      (nthcdr (car pos) world)
      (world-set (car (nthcdr (car pos) world)) (cdr pos) to) ))
  world)

(defun world-set-test ()
  (let ((ttt (make-world 2 3)) )
    (world-set ttt '(0 1) "a") ))

;; (world-set-test) ; (("." "a" ".") ("." "a" ".") ("." "a" "."))

(provide 'model)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-26 20:26       ` Emanuel Berg
@ 2022-12-27  1:12         ` Emanuel Berg
  2022-12-28  0:32           ` Emanuel Berg
  0 siblings, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2022-12-27  1:12 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun world-set (world pos to)
>   (if (= 1 (length pos))
>       (setcar (nthcdr (car pos) world) to)
>     (setcar
>       (nthcdr (car pos) world)
>       (world-set (car (nthcdr (car pos) world)) (cdr pos) to) ))
>   world)

Also not right ...

(defun world-set (world pos to)
  (if (= 1 (length pos))
      (setf (nth (car pos) world) to)
    (setcar
      (nthcdr (car pos) world)
      (world-set (nth (car pos) world)
                 (cdr pos)
                 to) ))
  world)

(defun world-set-test ()
  (let ((ttt (make-world 2 3)) )
    (world-set ttt '(0 1) "a") ))

;; (world-set-test) ; (("." "a" ".") ("." "a" ".") ("." "a" "."))

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-27  1:12         ` Emanuel Berg
@ 2022-12-28  0:32           ` Emanuel Berg
  2022-12-28  2:04             ` Emanuel Berg
                               ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Emanuel Berg @ 2022-12-28  0:32 UTC (permalink / raw)
  To: help-gnu-emacs

Why doesn't this work?

For sure, there is a mistake somewhere but it seems now matter how
I change it I get the same result ...

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/mvc/model.el

(require 'cl-lib)

(defun make-world (dim len &optional init)
  (or init (setq init "."))
  (if (zerop dim)
      init
    (make-list len (make-world (1- dim) len init)) ))

(defun world-size (world)
  (length (flatten-list world)) )

(defun make-world-test ()
  (let ((tests (list (list "cell"  (make-world 1 1)  1)
                     (list "ttt"   (make-world 2 3)  9)
                     (list "chess" (make-world 2 8) 64)
                     (list "cube"  (make-world 3 3) 27) )))
    (cl-loop
      for (name world expected) in tests
      and num-tests from 0 do
        (let ((size (world-size world)))
          (unless (= size expected)
            (error "World %s has size %s, expected %s" name size expected) ))
      finally return (= num-tests (length tests)) )))

;; (make-world-test)

(defun world-set (world pos to)
  (if (= 1 (length pos))
      (setf (nth (car pos) world) to)
    (world-set (nth (car pos) world) (cdr pos) to) ))

(defun world-set-test ()
  (let ((ttt (make-world 2 3)))
    (world-set ttt '(1 2) "o")
    ttt) )

;; (world-set-test)

(provide 'model)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-28  0:32           ` Emanuel Berg
@ 2022-12-28  2:04             ` Emanuel Berg
  2022-12-28  2:08             ` Emanuel Berg
  2022-12-28  9:25             ` tomas
  2 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2022-12-28  2:04 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun make-world (dim len &optional init)
>   (or init (setq init "."))
>   (if (zerop dim)
>       init
>     (make-list len (make-world (1- dim) len init)) ))

Okay, so maybe it's this part, so what's wrong with it?

Same stuff gets duplicated?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-28  0:32           ` Emanuel Berg
  2022-12-28  2:04             ` Emanuel Berg
@ 2022-12-28  2:08             ` Emanuel Berg
  2022-12-28  9:25             ` tomas
  2 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2022-12-28  2:08 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun make-world (dim len &optional init)
>   (or init (setq init "."))
>   (if (zerop dim)
>       init
>     (make-list len (make-world (1- dim) len init)) ))

So it was this part ...

Have a look, it's the same same list list!

(let ((lst (make-list 3 (list 1 2 3))))
  (setf (nth 2 (nth 1 lst)) 0)
  lst)

-> ((1 2 0) (1 2 0) (1 2 0))

$&#@%!

https://dataswamp.org/~incal/emacs-init/comic-book-insult.el

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-28  0:32           ` Emanuel Berg
  2022-12-28  2:04             ` Emanuel Berg
  2022-12-28  2:08             ` Emanuel Berg
@ 2022-12-28  9:25             ` tomas
  2022-12-28 19:53               ` Emanuel Berg
  2022-12-28 23:20               ` Emanuel Berg
  2 siblings, 2 replies; 14+ messages in thread
From: tomas @ 2022-12-28  9:25 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]

On Wed, Dec 28, 2022 at 01:32:52AM +0100, Emanuel Berg wrote:
> Why doesn't this work?
> 
> For sure, there is a mistake somewhere but it seems now matter how
> I change it I get the same result ...
> 
> ;;; -*- lexical-binding: t -*-
> ;;
> ;; this file:
> ;;   https://dataswamp.org/~incal/emacs-init/mvc/model.el
> 
> (require 'cl-lib)
> 
> (defun make-world (dim len &optional init)
>   (or init (setq init "."))
>   (if (zerop dim)
>       init
>     (make-list len (make-world (1- dim) len init)) ))

Heh. When you are making a higher-order world, you are
storing a ref to the same list in each of its slots.
So if you change something at a lower level *poof*
all are changed. Read the subsection "samenes and change"
in 3.1 of SICP [1] for a beautiful treatment (actually,
re-read SICP: a beautiful book)

Oh, I nearly forgot: if you want it to work, you'll
have to regenerate the lower-level worlds (or deep
copy them).

Cheers

[1] https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-20.html
    (Sorry: fragment links seem to be disfunctional)
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-28  9:25             ` tomas
@ 2022-12-28 19:53               ` Emanuel Berg
  2022-12-28 23:20               ` Emanuel Berg
  1 sibling, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2022-12-28 19:53 UTC (permalink / raw)
  To: help-gnu-emacs

tomas wrote:

> all are changed

No kidding!

It was a misunderstanding of `make-list' - in actuality,
a built-in/C _function_, so not a macro, i.e. the argument
INIT is evaluated and just once so - but I got it to work now:

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/mvc/model.el

(require 'cl-lib)

(defun make-world (dim len &optional init)
  (or init (setq init "."))
  (if (= 1 dim)
      (make-list len init)
    (let ((wrld '()))
      (dotimes (_ len)
        (push (make-world (1- dim) len init) wrld) )
      wrld) ))

;; (make-world 1 1)
;; (make-world 1 2)
;; (make-world 2 3)

(defun world-size (world)
  (length (flatten-list world)) )

(defun make-world-test ()
  (let ((tests (list (list "cell"  (make-world 1 1)  1)
                     (list "chess" (make-world 2 8) 64)
                     (list "cube"  (make-world 3 3) 27) )))
    (cl-loop
      for (name world expected) in tests
      and num-tests from 0 do
        (let ((size (world-size world)))
          (unless (= size expected)
            (error "World %s has size %s, expected %s" name size expected) ))
      finally return (= num-tests (length tests)) )))

;; (make-world-test)

(defun world-set (world pos to)
  (if (= 1 (length pos))
      (setf (nth (car pos) world) to)
    (world-set (nth (car pos) world) (cdr pos) to) ))

(defun world-set-test ()
  (let ((ttt (make-world 2 3)))
    (world-set ttt '(1 2) "o")
    ttt) )

;; (world-set-test)
;;     0   1   2
;; ( ("." "." ".")   0
;;   ("." "." "o")   1
;;   ("." "." ".") ) 2

(provide 'model)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Lisp Live buffer
  2022-12-28  9:25             ` tomas
  2022-12-28 19:53               ` Emanuel Berg
@ 2022-12-28 23:20               ` Emanuel Berg
  1 sibling, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2022-12-28 23:20 UTC (permalink / raw)
  To: help-gnu-emacs

And here is a little non-interactive demo ...

Now the live buffer is the next step, the "view" part.

Ideas?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-blank/mvc/model-ttt.el

(require 'model)

(defun ttt-board (&optional side blank)
  (or side (setq side 3))
  (or blank (setq blank "_"))
  (make-world 2 side blank) )

(let*((side    3)
      (blank   "_")
      (brd     (ttt-board side blank))
      (players '#1=("x" "o" . #1#) ))

  (defun ttt-set (x y)
    (interactive "nx: \nny: ")
    (let ((pos (list x y)))
      (when (string= blank (world-get brd pos))
        (world-set brd pos (pop players)) )))

  (declare-function ttt-set nil)

  (defun ttt-test-game ()
    (ttt-set 1 1)
    (ttt-set 0 0)
    (ttt-set 2 0)
    (ttt-set 0 2)
    (ttt-set 0 1)
    (ttt-set 2 1)
    (ttt-set 1 2)
    (ttt-set 1 0)
    (ttt-set 2 2)
    brd)

  (declare-function ttt-test-game nil) )

;; (ttt-test-game)
;; ( ("o" "x" "o")
;;   ("o" "x" "x")
;;   ("x" "o" "x") )

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-28 23:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 15:44 Lisp Live buffer Emanuel Berg
2022-12-07  3:06 ` Jean Louis
2022-12-07  3:54   ` Emanuel Berg
2022-12-23  8:15     ` Jean Louis
2022-12-26 20:26       ` Emanuel Berg
2022-12-27  1:12         ` Emanuel Berg
2022-12-28  0:32           ` Emanuel Berg
2022-12-28  2:04             ` Emanuel Berg
2022-12-28  2:08             ` Emanuel Berg
2022-12-28  9:25             ` tomas
2022-12-28 19:53               ` Emanuel Berg
2022-12-28 23:20               ` Emanuel Berg
2022-12-08 11:32 ` Madhu
2022-12-23  8:23   ` Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).