WIP: Optimize the project #23

Draft
kreyren wants to merge 1 commits from optimizations into central
Owner

Fixes: #22

DO NOT CONTRIBUTE: Needs to be redesigned

TODO

  • Rework the newly called "HANDLERS" meaning methods used to manage environmental variables into GNU Guile
  • Rework tests
  • Remove the Makefile interpretation functionality
Fixes: https://git.dotya.ml/kreyren/pman/issues/22 DO NOT CONTRIBUTE: Needs to be redesigned ### TODO - [ ] Rework the newly called "HANDLERS" meaning methods used to manage environmental variables into GNU Guile - [ ] Rework tests - [ ] Remove the `Makefile` interpretation functionality
kreyren added this to the Minimal usability milestone 2022-09-20 05:23:51 +02:00
kreyren added the
current-run
label 2022-09-20 05:23:51 +02:00
kreyren self-assigned this 2022-09-20 05:23:51 +02:00
kreyren added 1 commit 2022-09-20 05:23:53 +02:00
kreyren added spent time 2022-09-20 05:24:57 +02:00
11 hours 47 minutes
Author
Owner

11h47m research and abstracting

11h47m research and abstracting
Author
Owner
#!/usr/bin/env -S guile -e main -s    
!#    
(define targets     
  `(("nvim" . ,(lambda () (system "nvim")))    
    ("hello" . ,(lambda () (display "Hello, World!\n")))))    
(define (main args)    
  (let*    
    ((task (list-ref args 1))    
    (fun (assoc task targets)))    
    (if fun    
      ((cdr fun))     
      (display (append "task " task " not found!"))))) 

Solution through associated lists proposed

``` #!/usr/bin/env -S guile -e main -s !# (define targets `(("nvim" . ,(lambda () (system "nvim"))) ("hello" . ,(lambda () (display "Hello, World!\n"))))) (define (main args) (let* ((task (list-ref args 1)) (fun (assoc task targets))) (if fun ((cdr fun)) (display (append "task " task " not found!"))))) ``` Solution through associated lists proposed
Author
Owner
#!/usr/bin/env -S guile -e main -s
!#
(define (main args)
  (let*
      ((targets (let*
		    ((makes "makes/")
		     (sdir (opendir makes))
		     (suffx ".scm")
		     (targets '()))
		  (do ((sdirf (readdir sdir)))
		      ((eof-object? sdirf))
		    (set! sdirf (readdir sdir))
		    (when (and (string? sdirf) (string-suffix? suffx sdirf))
		      (primitive-eval
		       (let ((fil (open-file (string-append makes sdirf) "r")))
			 (set! targets (assoc-set! targets (substring sdirf 0 (+ 1 (string-suffix-length sdirf suffx))) (primitive-eval
															 `(lambda ()
															    ,(read fil)
															    ,(read fil))))))))
		    (set! targets
			  (assoc-set! targets "help"
				      (lambda (task)
					"Show the list of all commands and their docstrings"
					(display
					 (let ((e (assoc task targets)))
					   (string-append
					    (car e)
					    " : "
					    (procedure-documentation (cdr e))
					    "\n"))))))
		    (set! targets
			  (assoc-set! targets "tasks"
				      (lambda ()
					"Show the list of all commands and their docstrings"
					(map
					 (lambda (e)
					   (display
					    (string-append
					     (car e)
					     " : "
					     (procedure-documentation (cdr e))
					     "\n")))
					 targets)))))
		  targets))
       (task (list-ref args 1))
       (arg (list-tail args 2))
       (fun (assoc task targets)))
    (if fun
	(primitive-eval (append `(,(cdr fun)) arg))
	(display (string-append "task " task " not found!\n")))))

Alternative solution

```scm #!/usr/bin/env -S guile -e main -s !# (define (main args) (let* ((targets (let* ((makes "makes/") (sdir (opendir makes)) (suffx ".scm") (targets '())) (do ((sdirf (readdir sdir))) ((eof-object? sdirf)) (set! sdirf (readdir sdir)) (when (and (string? sdirf) (string-suffix? suffx sdirf)) (primitive-eval (let ((fil (open-file (string-append makes sdirf) "r"))) (set! targets (assoc-set! targets (substring sdirf 0 (+ 1 (string-suffix-length sdirf suffx))) (primitive-eval `(lambda () ,(read fil) ,(read fil)))))))) (set! targets (assoc-set! targets "help" (lambda (task) "Show the list of all commands and their docstrings" (display (let ((e (assoc task targets))) (string-append (car e) " : " (procedure-documentation (cdr e)) "\n")))))) (set! targets (assoc-set! targets "tasks" (lambda () "Show the list of all commands and their docstrings" (map (lambda (e) (display (string-append (car e) " : " (procedure-documentation (cdr e)) "\n"))) targets))))) targets)) (task (list-ref args 1)) (arg (list-tail args 2)) (fun (assoc task targets))) (if fun (primitive-eval (append `(,(cdr fun)) arg)) (display (string-append "task " task " not found!\n"))))) ``` Alternative solution
Author
Owner
scheme@(guile-user)> (define foo 2)
scheme@(guile-user)> (define bar 2)
scheme@(guile-user)> (map (lambda (s) (let ((b (symbol->string (car s)))) (if (string-match "^foo" b) s))) (hash-map->list cons (struct-ref (current-module) 0)))
$3 = ((foo . #<variable 7f31385b34a0 value: 2>) #<unspecified>)

Alternative solution

``` scheme@(guile-user)> (define foo 2) scheme@(guile-user)> (define bar 2) scheme@(guile-user)> (map (lambda (s) (let ((b (symbol->string (car s)))) (if (string-match "^foo" b) s))) (hash-map->list cons (struct-ref (current-module) 0))) $3 = ((foo . #<variable 7f31385b34a0 value: 2>) #<unspecified>) ``` Alternative solution
This pull request is marked as a work in progress.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin optimizations:optimizations
git checkout optimizations
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
1 Participants
Notifications
Total Time Spent: 11 hours 47 minutes
kreyren
11 hours 47 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: kreyren/pman#23
No description provided.