Dear #emacs and #org-mode comrades.
Given:
+ a table w/ a list of tags + their # of appearances per question 1 & 2.
+ org support for tag groups (https://orgmode.org/manual/Tag-Hierarchy.html)
+ GroupTag1=tagA+tagC+tagD and
+ GroupTag2=tagB+tagE
How can I count the sum of each group per question?
Example:
| tag | Q1 | Q2 |
|------+----+----|
| tagA | 9 | |
| tagB | 4 | 2 |
| tagC | 1 | 4 |
| tagD | | 5 |
| tagE | | 6 |
|------+----+----|
| GT1 | 10 | 9 |
| GT2 | 4 | 9 |
Thanks!
#tem25
@Eduardo Mercovich (él)
Well, I got this much working, which is sort of the crux of the problem. It takes a list of pairs and a function and applies the function repeatedly to the cdrs of the pairs that share the same car.
Roger has shown an expanded version of the table where the groups have been put against the values that apply to them. The last two columns of that table should be able to be turned into an appropriate list easily enough - I have not attempted this yet.
I'm in two minds about this as a solution for you.
On the one hand it's short, and has some general applicability beyond the stated problem.
On the other, I may be being a bit too clever - not quite 'week 1 of Lisp' material I suppose. Sticking to explicit iteration and solving the specific problem only would be more digestible. But this is the concrete thing that I got to first.
On the other other hand - I'm wondering whether there are library functions available to do this with fewer lines that I'm ignorant of.
Plus the use of the lambda in the application is a bit clunky - might be nicer to just pass + in (could just put in another layer of wrapping to do this).
And the function names might need some further thought...
But I thought I'd table it anyway — might be good to see some progress and perhaps it will inspire others to do better 😄
(defun assoc-replace (new alist)
"non-destructively replace the alist element with new, where the keys are equal"
(cl-substitute-if new
(lambda (x)
(equal (car x) (car new)))
alist))
(defun alist-acummulate-step (f alist pair)
"lookup alist using car pair and replace the element with f applied to the cdrs of it and pair. Add pair to alist if not found."
(let* ((key (car pair))
(old-pair (assoc key alist)))
(cond
(old-pair
(let ((result (funcall f (cdr old-pair) (cdr pair))))
(assoc-replace (list key result) alist)))
(t
(cons pair alist)))))
(defun alist-reduce (f pairs alist-initial)
"reduce using f into an alist with keys as the unique cars of pairs"
(seq-reduce
(lambda (x y) (alist-acummulate-step f x y))
pairs alist-initial))
Example of use:
(alist-reduce (lambda (x y) (+ (car x) (car y))) '((a 1) (b 2) (a 3) (c 4) (b 3) (b 4)) nil)
=>
((c 4) (b 9) (a 4))
#tem25 #elisp
Avalonia Visual Basic 6 is a recreation of the Visual Basic 6 IDE that also runs in the browser. It looks quite close to the original.
https://github.com/BAndysc/AvaloniaVisualBasic6
If someone proves me wrong (I could be!) it'll greatly improve my opinion of emacs.
What else can I share to better describe the thesis? Some parts that are not clear?
While #orgmode does 85% out of the box (#LiterateProgramming, tagging, counting, writing, exporting, even interacting with #gnuplot, etc.) #elisp is needed to do some of this calculations, ordering and grouping... :)
[end] #tem25
Tb hay partes q implican #elisp y #programacionliteraria. Pej integro 2 tablas con https://github.com/tbanel/orgtbljoin (genio tbanel) y debo ordenarla de forma específica. Se puede crear una función para hacer ése orden, y debe ser en elisp.
Querides Emacseres.
Necesito ayuda con #elisp para mi tesis (exploración de aprendizajes significativos para operar fuera de la academia) con #ProgramaciónLiteraria + #InvestigaciónReproducible. Y quiero q esté tan autocontenida en #Emacs (sí, soy un geek y estoy orgulloso) como sea posible. Sin embargo y aunque avanzo, encuentro mi elisp fu limitante.
¿Podría alguien ayudarme con esta tesis para mostrar el poder de Emacs y el #SoftwareLibre? Me encantará devolver con mis habilidades.
1e^3.Grcs
Dear Emacsers.
I need some help w/ #elisp for my #LiterateProgramming + #ReproducibleResearch thesis (an exploration of meaningful abilities to operate outside academia).
I'd like it as completely self contained in -and sustained by- #Emacs (yes, I'm a geek and I'm proud) as possible and, while going forward, I've found my #elisp fu limiting.
Can anyone share some time to help me with this thesis and show the power of Emacs and #FreeSoftware? I'd gladly share my abilities back.
1e^3.Thxs