https://chicoary.wordpress.com/2020/05/23/how-does-find-by-example-work-in-the-pharo-finder-englished/ Crab Log Um blog para todos e para ninguem... Menu Ir para conteudo * Inicial * Downloads * Filmes + Filmes vistos ate o ano passado * Leitura + Livros e artigos lidos ate o ano passado * Paleo Links * Projeto Tank Battle * SmallForth * Sobre mim * Translate * Tutorial de Pharo Smalltalk - Indice das licoes * Tutorial de Squeak + Introducao + Robots * Vela + Clima + Minha historia na Vela + Vela em grupo maio 23, 2020maio 24, 2020 chicoary How does find by example work in the Pharo Finder [Englished] Veja o post original em portugues em How does find by example work in the Pharo Finder. How does find by example work in the Pharo Finder One of the things that looks like magic is the search for methods through examples. But we will see that there is no black magic in this if we take into account the fantastic reflection capacity of Pharo Smalltalk . The tool is available from Squeak , from which Pharo descends. Let's do an experiment with the Finder . We are going to provide a shuffled array and the same ordered array . See How to find methods based on examples in the Pharo Tutorial . Using the Finder Open the Finder. [world-tool] Provide the arrays . [finder-sea] See the results. [finder-by-] Finder Script Now we want to create a script to do the same, roughly. We will avoid creating new classes and methods using block closures . We will develop the script gradually. Initially we will check the partial results of the computation. We start by obtaining the example parameters and the class hierarchy that can contain the methods sought. [class-hier] The example is passed as an array . The first element is the recipient of the message. The last is the returned value. The intermediate values are the arguments of the message. The internal hierarchy closure recursively navigates up the class hierarchy. In our case, 4 classes are obtained. We excluded the Object classes and superclasses from it. [class-hier] Let's get all the methods in the class hierarchy. [all-method] We use flatCollect : instead of collect : to get the flatten of the array of arrays . Each class would return an array with their methods within another array if we used the collect :. [all-method] We see that we have obtained many methods that are not of interest since our example is an array with two elements. From this array we get the receiver and the result of the method. There are no arguments. Soon the message is unary, with no argument. So let's filter the methods further. We will initially filter the number of arguments. [filtering-] Now we only have unary methods on the list. [filtering-] And finally we will add the filter for the methods that return the result of the example. [final-vers] We take care to predict the possibility of an error in the method. In this case it is excluded from the list. [final-vers] Below the script code : findMethodByExample := [ :example | | receiver arguments result class hierarchy | receiver := example first. arguments := example allButFirst allButLast. result := example last. class := receiver class. hierarchy := [ :clazz | clazz = Object ifTrue: [ { } ] ifFalse: [ { clazz }, (hierarchy value: clazz superclass) ]. ]. ((hierarchy value: class) flatCollect: [ :aClass | aClass methods ]) select: [ :method | method numArgs = arguments size and: [ [((Message selector: method selector arguments: arguments) sendTo: receiver deepCopy) = result] on: Error do: [ false ] ] ]. ]. findMethodByExample value: { #(1 2 3 4 5 6 7 8 9) shuffled. #(1 2 3 4 5 6 7 8 9) }. Combining results We will now try to combine the results of several simultaneous examples to reduce the size of the possibilities. Let's imagine that we are trying to get the name of the method to round a number. Our example below shows several methods not related to rounding. Our example is a little artificial but will serve to illustrate the idea. [truncated-] We then try another example. And it gets better. [rounded-an] We then decided to combine the two examples and the result is narrower. [finder-by-] Combining results with the Finder Can we do the same with the Finder? Perhaps... Question How does find-by-example work in the Pharo Finder? on the Stack Overflow website suggests that we investigate the MethodFinder class. [methodfind] There are two methods: findMethodsByExampleInput:andExpectedResult: e possibleSolutionsForInput: The first invokes the second and has arguments compatible with what we need. We repeated with MethodFinder the examples {2.4. 2} and {2.5. 3} . [methodfind] [methodfind] We can naively try to get the combination of the examples and get nothing! [methodfind] The reason for the failure is due to the fact that MethodFinder >> findMethodsByExampleInput: andExpectedResult: returns a collection of instances of the MethodFinderSend class . [methodfind] We noticed that there is the Met hodFinderSend >> selector method that we can use to correct the problem. [methodfind] Now we have obtained the list, with a single element for this case, of method selectors. [methodfind] If you click on the list you will get more information about the methods that implement the message represented by the selector. [message-se] [porkey] Compartilhe isso: * Twitter * Mais * * WhatsApp * E-mail * * Facebook * Telegram * * Curtir isso: Curtir Carregando... Relacionado * Pharo * Programming * Smalltalk [105c224029ed87b1] Publicado por chicoary Ver todos os posts por chicoary Navegacao de posts Anterior Visual feedback on Pharo Smalltalk using Watchpoints Proximo Visual feedback on Pharo Smalltalk using Watchpoints [Englished] Um comentario 1. [b933a8518b596198] How does find by example work in the Pharo Finder - Crab Log disse: maio 23, 2020 as 11:26 am [...] See an English version via automatic translation with Google Translator in How does find by example work in the Pharo Finder [Englished]. [...] Responder Deixe um comentario Cancelar resposta Digite seu comentario aqui... [ ] Preencha os seus dados abaixo ou clique em um icone para log in: * * * * Gravatar Email (obrigatorio) (Nunca tornar endereco publico) [ ] Nome (obrigatorio) [ ] Site [ ] Logotipo do WordPress.com Voce esta comentando utilizando sua conta WordPress.com. ( Sair / Alterar ) Imagem do Twitter Voce esta comentando utilizando sua conta Twitter. ( Sair / Alterar ) Foto do Facebook Voce esta comentando utilizando sua conta Facebook. ( Sair / Alterar ) Cancelar Conectando a %s [ ] Avise-me sobre novos comentarios por email. [ ] Avise-me sobre novas publicacoes por email. [Publicar comentario] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] Busca Pesquisar por: [ ] [Pesquisar] Tradutor Translate this weblog 02bandeira-eua01bandeira-ingla By Ferramentas Blog Visitantes Map Tags Cidade & Regiao Cinema Citacao Ciencia Cotidiano Cultura Dieta Paleolitica Esporte Evento Filosofia Humor Literatura Livro Musica Noticias Pharo Politica post-citacao Programming Saude Smalltalk Software Software engineering Tecnologia Textos Tutorial Uncategorized Vela Video Web Posts recentes * Leontiev e a Ucrania * Mate in 1 * Mate em 1 * Russia fala em armas nucleares; ocidente trata de sistema SWIFT... * A Polonia tem a chave para desescalar as tensoes Russia-NATO? maio 2020 S T Q Q S S D 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 << abr jun >> Admin * Cadastre-se * Fazer login * Feed de posts * Feed de comentarios * WordPress.com Blogroll * Amalgama * Beto * Bigorna * Ceticismo * Clement Bera ~ Smalltalk, Tips 'n Tricks * Crab Blog * Curtindo Viajar * Dicas da Pukka * Dieta Low-Carb e Paleolitica * Dirceu Tiegs * ditoinfo * Dragao da Garagem * Griff Tour * Iasmin * JazzMan! * Lambda the Ultimate * Life Hacker * Mateus * Mateus * My blinks * O caderno de Saramago * obvious * On Smalltalk * Paintball Sergipe * Portal do Video * Projeto Ockham * Releituras * Rodrigo Maues Rocha * Taijiquan Pro * The OOPSLA diaries * Uma Coisa e Outra * Uma outra visao * Veleiro Net * WordPress.com * WordPress.org Filosofia * Razao Inadequada Homepage * Netvibes * Protopage HQ * Bigorna Humor * Redatoras de Merda Pharo * Clement Bera ~ Smalltalk, Tips 'n Tricks Ruby * RubyOnBR Smalltalk * Clement Bera ~ Smalltalk, Tips 'n Tricks Software * Clement Bera ~ Smalltalk, Tips 'n Tricks * Lukas Renggli Arquivos * marco 2022 * fevereiro 2022 * janeiro 2022 * dezembro 2021 * novembro 2021 * outubro 2021 * setembro 2021 * agosto 2021 * julho 2021 * junho 2021 * maio 2021 * abril 2021 * marco 2021 * fevereiro 2021 * janeiro 2021 * dezembro 2020 * novembro 2020 * outubro 2020 * agosto 2020 * julho 2020 * junho 2020 * maio 2020 * abril 2020 * marco 2020 * fevereiro 2020 * novembro 2019 * outubro 2019 * setembro 2019 * agosto 2019 * julho 2019 * junho 2019 * maio 2019 * abril 2019 * marco 2019 * fevereiro 2019 * janeiro 2019 * dezembro 2018 * novembro 2018 * outubro 2018 * setembro 2018 * agosto 2018 * julho 2018 * junho 2018 * maio 2018 * abril 2018 * marco 2018 * fevereiro 2018 * janeiro 2018 * dezembro 2017 * novembro 2017 * outubro 2017 * setembro 2017 * agosto 2017 * julho 2017 * junho 2017 * maio 2017 * abril 2017 * marco 2017 * fevereiro 2017 * janeiro 2017 * dezembro 2016 * novembro 2016 * outubro 2016 * setembro 2016 * agosto 2016 * julho 2016 * junho 2016 * maio 2016 * abril 2016 * marco 2016 * fevereiro 2016 * janeiro 2016 * dezembro 2015 * novembro 2015 * outubro 2015 * setembro 2015 * agosto 2015 * julho 2015 * junho 2015 * maio 2015 * abril 2015 * marco 2015 * fevereiro 2015 * janeiro 2015 * dezembro 2014 * novembro 2014 * outubro 2014 * setembro 2014 * agosto 2014 * julho 2014 * junho 2014 * maio 2014 * abril 2014 * marco 2014 * fevereiro 2014 * janeiro 2014 * dezembro 2013 * novembro 2013 * outubro 2013 * setembro 2013 * agosto 2013 * julho 2013 * maio 2013 * abril 2013 * marco 2013 * fevereiro 2013 * janeiro 2013 * dezembro 2012 * novembro 2012 * outubro 2012 * setembro 2012 * agosto 2012 * julho 2012 * junho 2012 * maio 2012 * abril 2012 * marco 2012 * fevereiro 2012 * dezembro 2011 * novembro 2011 * outubro 2011 * setembro 2011 * julho 2011 * junho 2011 * maio 2011 * abril 2011 * marco 2011 * fevereiro 2011 * janeiro 2011 * dezembro 2010 * novembro 2010 * outubro 2010 * setembro 2010 * agosto 2010 * julho 2010 * junho 2010 * maio 2010 * abril 2010 * marco 2010 * fevereiro 2010 * janeiro 2010 * dezembro 2009 * novembro 2009 * outubro 2009 * setembro 2009 * julho 2009 * junho 2009 * maio 2009 * abril 2009 * marco 2009 * fevereiro 2009 * dezembro 2008 * novembro 2008 * outubro 2008 * setembro 2008 * agosto 2008 * julho 2008 * junho 2008 * maio 2008 * abril 2008 * marco 2008 * fevereiro 2008 * dezembro 2007 * novembro 2007 * outubro 2007 * setembro 2007 * agosto 2007 * julho 2007 * junho 2007 * maio 2007 * abril 2007 * marco 2007 * fevereiro 2007 * janeiro 2007 * dezembro 2006 * outubro 2006 * setembro 2006 * agosto 2006 * julho 2006 * junho 2006 * maio 2006 * abril 2006 * marco 2006 * fevereiro 2006 * janeiro 2006 WordPress.com. * Seguir Seguindo + [b933a8] Crab Log [ ] Cadastre-me + Ja tem uma conta do WordPress.com? Faca login agora. * + [b933a8] Crab Log + Personalizar + Seguir Seguindo + Registre-se + Fazer login + Copiar link curto + Denunciar este conteudo + Ver post no Leitor + Gerenciar assinaturas + Esconder esta barra Carregando comentarios... Escreva um Comentario [ ] E-mail (obrigatorio) [ ] Nome (obrigatorio) [ ] Site [ ] [Publicar comentario] Enviar para oendereco de e-mail [ ] Seu nome [ ] Seu endereco de e-mail [ ] [ ] loading [Enviar e-mail] Cancelar Post nao foi enviado - verifique os seus enderecos de e-mail! Verificacao de e-mail falhou, tente novamente Desculpe, seu blog nao pode compartilhar posts por e-mail. %d blogueiros gostam disto: [b]